PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000067. Sự cố mạng lưới (Network Breakdown)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sự cố mạng lưới (Network Breakdown)

Network Breakdown

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected network consists of nn computers and mm connections. Computers belong to the same connected component if they can communicate through functioning connections. Once a connection breaks, it is never restored.

There are kk breakdowns, each removing one connection that is still present. Report the number of connected components after each breakdown, including isolated computers.

All connections are undirected, so (a,b)(a,b) and (b,a)(b,a) identify the same connection. Every initial connection appears once, and the failures identify the exact edges to remove. A failed edge does not fail a second time.

Two computers belong to the same connected component when a path consisting of working connections exists between them. An isolated computer also constitutes a component. Report the component count after every failure, even if the count does not change.

Input

The first line contains n,m,kn,m,k. The next mm lines each specify a connection a,ba,b. The last kk lines specify the connection to remove in order.

Output

Print kk integers in order, one for each breakdown, giving the number of connected components afterwards.

Subtasks

  • Subtask 1 (20 points): 2≤n≤302\le n\le 30; 1≤m≤1201\le m\le 120; 1≤k≤1201\le k\le 120; 1≤a,b≤n1\le a,b\le n, a≠ba\ne b; all initial edges are distinct; each removed edge appears in the initial graph and is removed exactly once.
  • Subtask 2 (30 points): 2≤n≤30002\le n\le 3000; 1≤m≤60001\le m\le 6000; 1≤k≤50001\le k\le 5000; 1≤a,b≤n1\le a,b\le n, a≠ba\ne b; all initial edges are distinct; each removed edge appears in the initial graph and is removed exactly once.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000; 1≤m≤2000001\le m\le 200000; 1≤k≤2000001\le k\le 200000; 1≤a,b≤n1\le a,b\le n, a≠ba\ne b; all initial edges are distinct; each removed edge appears in the initial graph and is removed exactly once.

Examples

Input

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

Output

2 2 3

Explanation

Removing edge (3,4)(3,4) separates the network into {1,2,3}\{1,2,3\} and {4,5}\{4,5\}. Deleting edge (2,3)(2,3) does not split the first component because the route 2o1o32 o1 o3 still exists. Finally, deleting edge (4,5)(4,5) isolates computer 55, so the numbers of components are 2,2,32,2,3.