#DSU0000066. Những cây cầu xuống cấp (Decayed Bridges)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những cây cầu xuống cấp (Decayed Bridges)
Decayed Bridges
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are islands connected by undirected bridges. Initially, every island can be reached from every other island. Bridges collapse in this order and cannot be used afterwards.
After each collapse, the inconvenience is the number of pairs , , such that no path between and remains. Find the inconvenience after every collapse.
The bridges are numbered by their order in the input. When one bridge collapses, only that bridge disappears; all other bridges remain usable. A pair of islands is counted as disconnected only when no path between them remains, even if the previous path went through several intermediate islands.
Initially all islands are mutually reachable. After every bridge has collapsed, none of them are connected to another. Each requested answer refers to the graph immediately after the corresponding collapse, not just before it.
Input
The first line contains . Each of the next lines contains , the endpoints of bridge .
Output
Print lines. Line contains the number of disconnected unordered island pairs after the first bridges collapse.
Subtasks
- Subtask 1 (20 points): ; ; ; every pair of endpoints is distinct; the initial graph is connected.
- Subtask 2 (30 points): ; ; ; every pair of endpoints is distinct; the initial graph is connected.
- Subtask 3 (50 points): ; ; ; every pair of endpoints is distinct; the initial graph is connected.
Examples
Input
4 5
1 2
3 4
1 3
2 3
1 4
Output
0
0
4
5
6
Explanation
The first two bridge collapses leave the graph connected, so both answers are . After edge collapses, the remaining components are and , yielding disconnected pairs. The next collapse gives disconnected pairs. After the last bridge collapses, all inom{4}{2}=6 pairs are disconnected.