cswork / OAOpen practice workspace

RubrikOA #2

Social Connections (Visible Profiles per Query)

Estimated MediumJudge-ready

Topics (AI-labelled)Union-Find

You are given an undirected social graph. Each queried user can see all users in their connected component (including themselves); for each query, in the original order, output the size of that connected component.

Input

The first line is N E Q; then E lines follow, each an undirected edge u v; the last line contains Q queried user numbers. The OAMaster examples use 1-based user numbers; this site specifies 1≤N≤200000, 0≤E,Q≤200000 with E+Q≤200000, and all numbers in 1..N. Duplicate edges and self-loops are allowed (neither changes the connected components).

Output

Output one line with Q integers: for each query in order, the number of vertices in that user's connected component.

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:

1 0 1
1

Output:

1

Example 3

Input:

4 3 3
1 2
2 3
3 4
1 2 4

Output:

4 4 4

Editorial

Loading solution…