#P3180. [HAOI2016] 地图
[HAOI2016] 地图
Description
One day, rin came to a distant metropolis. The city has buildings, numbered to , with the city center being building . There are bidirectional streets, each connecting two buildings, and some streets connect end to end to form a cycle.
After long observation, rin has learned two facts about this city:
- From the city center, all buildings are reachable.
- Any street belongs to at most one simple cycle.
Every building sells ramen. There are many kinds of ramen, but for rin only the greasiness level matters, so we treat ramen with the same greasiness level as the same type. We use a positive integer to denote the greasiness level.
It is rush hour, and traffic is very jammed. rin can only travel along streets that are not blocked.
Now rin wants to know: if she is at building , and all streets lying on every simple path from the city center to are blocked, then among the ramen she can taste (note that types that do not appear at all must not be counted):
- How many types have greasiness and appear an odd number of times?
- How many types have greasiness and appear an even number of times? Here “even” means a positive even number of occurrences; types with zero occurrences are not counted.
Constraints:
- , , , .
Input Format
- The first line contains two positive integers .
- The second line contains positive integers; the -th number is the greasiness level of the ramen sold at building .
- The next lines each contain two positive integers , meaning there is a bidirectional street between buildings and . It is guaranteed that .
- The next line contains a single positive integer , the number of queries.
- The next lines each contain three non-negative integers . When , it asks for the count of types with an even number of occurrences; when , it asks for the count of types with an odd number of occurrences.
Output Format
Output lines. For each query, output a single integer: the answer to that query.
10 12
1 10 4 5 2 10 1 8 4 8
1 2
1 3
1 4
2 5
4 6
4 7
7 8
2 9
8 10
1 6
8 10
4 7
10
0 3 9
1 7 6
0 5 2
1 10 9
0 5 7
1 7 4
0 7 3
1 2 7
0 3 4
0 3 8
0
1
0
1
0
1
0
2
0
0
Hint
Please pay attention to the in Constraints. The mentioned above is the in the queries. For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号