Navy
Time limit25sMemory limit1024 MB
For each night t, count the rivers whose removal splits the graph, where the rivers are the union of the sets A for weather B_t and B_(t+1).
- Level
Hard9 of 10
- Topics
- Divide and conquer, Union-find, Graph
- Solved
- No attempts yet
Problem
Byteland has lakes, and some rivers directly connect pairs of lakes. You are the naval commander of Byteland, and you want to plan a strategy for the coming war.
Byteland's intelligence service reports that the war will last days, and that a battle takes place on each night between consecutive days. That is, for every , a battle takes place on the night between day and day .
Treat the lakes and rivers of Byteland as a graph. If removing a river increases the number of connected components, the river is called a critical river. (In graph theory, such a river is called a cut edge.)
Lakes always hold water, but rivers may dry up depending on the weather. That is, a pair of lakes may or may not be directly connected by a river. Byteland has kinds of weather, and weather creates a river for each pair of lakes in the set .
Scientists found the weather for each day from to . Scientists predicted that on the night between day and day , when a battle takes place, the set of rivers is .
Using these predictions, output the number of critical rivers for each of the battles.
A set may contain the same element two or more times (a multiset), and the lakes and rivers may not form a planar graph.
Input
The first line contains three integers , , and . (, )
The second line contains integers . ()
The next lines describe the sets . Each line contains integers. The first integer is the size of . The next integers list, in order, the numbers of the lakes that each pair of lakes in that weather connects. The two lake numbers in each pair are different.
The sum of all does not exceed .
Output
Print lines. Line contains the number of critical rivers for the -th battle.