A9682 | Mr. Kitayuta's Colorful Graph
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Mr. Kitayuta has just bought an undirected graph consisting of $n$ vertices and $m$ edges. The vertices of the graph are numbered from 1 to $n$ . Each edge, namely edge $i$ , has a color $c_{i}$ , connecting vertex $a_{i}$ and $b_{i}$ .
Mr. Kitayuta wants you to process the following $q$ queries.
In the $i$ -th query, he gives you two integers — $u_{i}$ and $v_{i}$ .
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex $u_{i}$ and vertex $v_{i}$ directly or indirectly.
Mr. Kitayuta wants you to process the following $q$ queries.
In the $i$ -th query, he gives you two integers — $u_{i}$ and $v_{i}$ .
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex $u_{i}$ and vertex $v_{i}$ directly or indirectly.
输入格式
The first line of the input contains space-separated two integers — $n$ and $m$ ( $2<=n<=100,1<=m<=100$ ), denoting the number of the vertices and the number of the edges, respectively.
The next $m$ lines contain space-separated three integers — $a_{i}$ , $b_{i}$ ( $1<=a_{i}<b_{i}<=n$ ) and $c_{i}$ ( $1<=c_{i}<=m$ ). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if $i≠j$ , $(a_{i},b_{i},c_{i})≠(a_{j},b_{j},c_{j})$ .
The next line contains a integer — $q$ ( $1<=q<=100$ ), denoting the number of the queries.
Then follows $q$ lines, containing space-separated two integers — $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ ). It is guaranteed that $u_{i}≠v_{i}$ .
The next $m$ lines contain space-separated three integers — $a_{i}$ , $b_{i}$ ( $1<=a_{i}<b_{i}<=n$ ) and $c_{i}$ ( $1<=c_{i}<=m$ ). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if $i≠j$ , $(a_{i},b_{i},c_{i})≠(a_{j},b_{j},c_{j})$ .
The next line contains a integer — $q$ ( $1<=q<=100$ ), denoting the number of the queries.
Then follows $q$ lines, containing space-separated two integers — $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ ). It is guaranteed that $u_{i}≠v_{i}$ .
输出格式
For each query, print the answer in a separate line.
输入输出样例
输入 #1
4 5 1 2 1 1 2 2 2 3 1 2 3 3 2 4 3 3 1 2 3 4 1 4
输出 #1
2 1 0
输入 #2
5 7 1 5 1 2 5 1 3 5 1 4 5 1 1 2 2 2 3 2 3 4 2 5 1 5 5 1 2 5 1 5 1 4
输出 #2
1 1 1 1 2
Let's consider the first sample.
 The figure above shows the first sample. - Vertex $1$ and vertex $2$ are connected by color $1$ and $2$ .
- Vertex $3$ and vertex $4$ are connected by color $3$ .
- Vertex $1$ and vertex $4$ are not connected by any single color.
 The figure above shows the first sample. - Vertex $1$ and vertex $2$ are connected by color $1$ and $2$ .
- Vertex $3$ and vertex $4$ are connected by color $3$ .
- Vertex $1$ and vertex $4$ are not connected by any single color.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted