cswork / OAOpen practice workspace

IBMOA #71

Visible Profiles Count

Estimated MediumJudge-ready

Topics (AI-labelled)Union-Find

Users are numbered 1..n, and undirected connections can be followed over multiple hops. Each query returns the number of users in that user's connected component, including the user; the answer for an isolated user is 1. The original example wrote the visible list of an isolated node as empty, yet explicitly counted the user themselves; this statement corrects it accordingly.

Input

The first line contains n m q, followed by m lines of edges u v, and finally q query numbers. This site adds 1≤n,q≤200000, 0≤m≤200000, and all endpoints and queries are in 1..n. Self-loops and multiple edges are allowed, and the graph need not be connected.

Output

Output q integers in query order.

Example 1

Input:

7 4 4
1 2
2 3
3 4
5 6
1 3 5 7

Output:

4 4 2 1

Example 2

Input:

3 0 3
1 2 3

Output:

1 1 1

Example 3

Input:

3 3 3
1 1
1 2
2 1
1 3 2

Output:

2 1 2

Example notes

The outputs of the three public examples are, in order: 4 4 2 1; 1 1 1; 2 1 2. These answers were verified by independent enumeration or direct simulation.

Editorial

Loading solution…