PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000005. Thi công đường (Road Construction)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thi công đường (Road Construction)
Road Construction
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities and initially no roads. Over days, one bidirectional road is built each day. After each day, determine the number of connected components and the size of the largest connected component.
Input
The first line contains two integers . Each of the next lines contains two integers , specifying the road built on that day. Cities are numbered from to .
Output
After each day, print two integers: the number of connected components and the size of the largest one.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
5 3
1 2
1 3
4 5
Output
4 2
3 3
2 3
Explanation
After 1–2 there are four components, largest size 2; after 1–3, three components and size 3; after 4–5, two components and size 3.