#DSU0000067. Sự cố mạng lưới (Network Breakdown)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sự cố mạng lưới (Network Breakdown)
Network Breakdown
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected network consists of computers and 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 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 and 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 . The next lines each specify a connection . The last lines specify the connection to remove in order.
Output
Print integers in order, one for each breakdown, giving the number of connected components afterwards.
Subtasks
- Subtask 1 (20 points): ; ; ; , ; all initial edges are distinct; each removed edge appears in the initial graph and is removed exactly once.
- Subtask 2 (30 points): ; ; ; , ; all initial edges are distinct; each removed edge appears in the initial graph and is removed exactly once.
- Subtask 3 (50 points): ; ; ; , ; 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 separates the network into and . Deleting edge does not split the first component because the route still exists. Finally, deleting edge isolates computer , so the numbers of components are .