#DSU0000074. Các thành phần liên thông (Connected Components)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các thành phần liên thông (Connected Components)
Connected Components
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A network has computers and indexed undirected cables. Multiple cables may connect the same pair of computers.
There are independent experiments. In experiment , cables numbered through are disconnected temporarily, and the number of connected components is measured. All cables are restored before the next experiment. An isolated computer counts as one component.
Cables are indexed by their input order, so two cables joining the same pair of computers remain distinct cables. Removing the interval disables all cables with indices in that interval, including both endpoints.
Each query is an independent experiment: after counting connected components, all cables disabled in that experiment are restored. Therefore, an earlier query never changes the initial state for a later query.
Input
The first line contains , followed by pairs . The next line contains , followed by intervals .
Output
Print integers. Integer is the component count during experiment .
Subtasks
- Subtask 1 (20 points): ; ; ; , ; parallel edges are allowed; .
- Subtask 2 (30 points): ; ; ; , ; parallel edges are allowed; .
- Subtask 3 (50 points): ; ; ; , ; parallel edges are allowed; .
Examples
Input
6 5
1 2
5 4
2 3
3 1
3 6
6
1 3
2 5
1 5
5 5
2 4
3 3
Output
4
5
6
3
4
2
Explanation
Each answer is computed from the original network with exactly the query's indexed cable interval disabled. The values refer to six independent experiments. Cables disabled by one query are restored before the next query begins.