#P6328. 我是仙人掌
我是仙人掌
Description
Chtholly gives you an undirected graph. In each query, you are given a set of pairs .
Find how many vertices in the graph satisfy, for at least one pair in this query, , where denotes the distance between the two vertices in the graph.
If two vertices are disconnected, then .
Input Format
The first line contains three integers .
is the number of vertices, and is the number of edges.
Then follow lines, each containing two integers , indicating that there is an edge between these two vertices. All edge weights are .
Then there are queries. For each query, you are first given an integer .
Then follow lines, each containing two integers , representing a pair.
Output Format
Output lines. Each line contains one integer, the answer to the corresponding query.
5 6 6
2 3
1 3
2 5
1 3
3 2
2 5
1
3 1
1
1 1
1
1 4
1
5 2
1
1 4
2
1 0
5 1
3
2
4
3
4
3
Hint
Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477.
Constraints: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号