luogu#P6328. 我是仙人掌
我是仙人掌
Background
I kept the...
agreement... an agreement.

【You are working very hard.】
I am working very, very hard...

【Even though you said that yesterday too...】
【Welcome back, Chtholly.】

I'm back...
I finally said it out loud...
【Yes, I finally heard it.】
Will red hair look strange?
【It is a very pretty color, it suits you well.】
Really...
I... I'm fine now.
【Really? Is your condition okay?】
【If you are forcing yourself, I won't let you off.】
It's fine. Cooking, laundry... there is still a lot of work to do.
【Don't push yourself too hard.】

Hmph, just be mentally prepared and wait.

Problem 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