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

#DSU0000072. Mất điện (Blackout 2)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Mất điện (Blackout 2)

Blackout 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A region has NN cities and MM power plants. Locations 1,…,N1,\ldots,N are cities, and locations N+1,…,N+MN+1,\ldots,N+M are power plants. There are EE bidirectional power lines.

A city is electrified if it can reach at least one power plant through functioning lines. In QQ successive events, power line XiX_i breaks permanently. Determine the number of electrified cities immediately after each event.

Power plants supply electricity but are not included in the number of electrified cities. A city is counted once if it can reach at least one power plant, regardless of how many plants it can reach.

Each failure is given by the index of a power line in the original list, not by a vertex number. The failed line indices are distinct, and a broken line never returns to service.

Input

The first line contains N,M,EN,M,E, followed by EE lines of endpoints Ui,ViU_i,V_i. Next comes QQ and then QQ line indices XiX_i.

Output

Print QQ lines; line ii is the number of electrified cities after event ii.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le 20; 1≤M≤201\le M\le 20; 1≤E≤1201\le E\le 120; 1≤Q≤1201\le Q\le 120; N+M≤2⋅105N+M\le 2\cdot10^5; 1≤Ui<Vi≤N+M1\le U_i<V_i\le N+M; power lines are distinct; Q≤EQ\le E and the indices XiX_i are distinct integers in [1,E][1,E].
  • Subtask 2 (30 points): 1≤N≤15001\le N\le 1500; 1≤M≤15001\le M\le 1500; 1≤E≤60001\le E\le 6000; 1≤Q≤30001\le Q\le 3000; N+M≤2⋅105N+M\le 2\cdot10^5; 1≤Ui<Vi≤N+M1\le U_i<V_i\le N+M; power lines are distinct; Q≤EQ\le E and the indices XiX_i are distinct integers in [1,E][1,E].
  • Subtask 3 (50 points): 1≤N≤1000001\le N\le 100000; 1≤M≤1000001\le M\le 100000; 1≤E≤5000001\le E\le 500000; 1≤Q≤5000001\le Q\le 500000; N+M≤2⋅105N+M\le 2\cdot10^5; 1≤Ui<Vi≤N+M1\le U_i<V_i\le N+M; power lines are distinct; Q≤EQ\le E and the indices XiX_i are distinct integers in [1,E][1,E].

Examples

Input

5 5 10
2 3
4 10
5 10
6 9
2 9
4 8
1 7
3 6
8 10
1 8
6
3
5
8
10
2
7

Output

4
4
2
2
2
1

Explanation

Initially all five cities are electrified. The first failure disconnects city 55 from the power network, leaving four electrified cities. The second failure does not change the count. The third failure removes electricity from cities 2,32,3, leaving two. The fourth and fifth failures leave the count unchanged; the last failure leaves only one electrified city.