#P10657. BZOJ4998 星球联盟
BZOJ4998 星球联盟
Problem Description
In the distant S galaxy, there are planets in total, numbered from to . Some of these planets decide to form an alliance to make communication between them easier. However, the first condition for forming an alliance is the transportation condition.
Initially, there are space tunnels among these planets. Each space tunnel connects two planets so that they can reach each other. If two planets belong to the same alliance, then there must exist a cycle route that passes through both planets, that is, there are two paths between the two planets that do not share any common tunnels. To expand the alliance, these planets will build new space tunnels. These new tunnels will be built one by one in order. After a new tunnel is built, it may cause some planets to belong to the same alliance.
Your task is: after each new tunnel is completed, determine whether the two planets connected by this new tunnel belong to the same alliance. If they belong to the same alliance, compute how many planets are in this alliance.
Input Format
The first line contains three integers , representing the total number of planets, the number of initial space tunnels, and the number of tunnels to be built.
Lines to each contain two integers, representing the indices of the two planets connected by each initial space tunnel.
Lines to each contain two integers, representing the indices of the two planets connected by each newly built space tunnel.
These space tunnels are built one by one in the order given in the input.
Output Format
Output lines in total:
- If the two planets connected by this new space tunnel belong to the same alliance, output one integer, which is the number of planets in the alliance that contains these two planets.
- If the two planets connected by this new space tunnel do not belong to the same alliance, output
No.
5 3 4
1 2
4 3
4 5
2 3
1 3
4 5
2 4
No
3
2
5
Hint

Constraints: .
Translated by ChatGPT 5