#DSU0000072. Mất điện (Blackout 2)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mất điện (Blackout 2)
Blackout 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A region has cities and power plants. Locations are cities, and locations are power plants. There are bidirectional power lines.
A city is electrified if it can reach at least one power plant through functioning lines. In successive events, power line 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 , followed by lines of endpoints . Next comes and then line indices .
Output
Print lines; line is the number of electrified cities after event .
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; power lines are distinct; and the indices are distinct integers in .
- Subtask 2 (30 points): ; ; ; ; ; ; power lines are distinct; and the indices are distinct integers in .
- Subtask 3 (50 points): ; ; ; ; ; ; power lines are distinct; and the indices are distinct integers in .
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 from the power network, leaving four electrified cities. The second failure does not change the count. The third failure removes electricity from cities , leaving two. The fourth and fifth failures leave the count unchanged; the last failure leaves only one electrified city.