#P10657. BZOJ4998 星球联盟

BZOJ4998 星球联盟

Problem Description

In the distant S galaxy, there are nn planets in total, numbered from 11 to nn. 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 mm space tunnels among these nn 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 pp new space tunnels. These pp 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 n,m,pn, m, p, representing the total number of planets, the number of initial space tunnels, and the number of tunnels to be built.

Lines 22 to m+1m + 1 each contain two integers, representing the indices of the two planets connected by each initial space tunnel.

Lines m+2m + 2 to m+p+1m + p + 1 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 pp 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: 1n,m,p2×1051 \le n, m, p \le 2 \times 10^5.

Translated by ChatGPT 5