PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000091. Nối các điểm (Connect the Dots)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nối các điểm (Connect the Dots)
Connect the Dots
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are points numbered from to , initially with no connections. Each of the operations selects points and connects every pair of selected points. After all operations, determine the number of connected components in the resulting undirected graph. Operations may add redundant connections.
Input
The first line contains . Each of the next lines contains .
Output
Print the number of connected components.
Subtasks
- Subtask 1 (20 points): , , , , .
- Subtask 2 (30 points): , , , , .
- Subtask 3 (50 points): , , , .
Examples
Input
10 2
1 2 4
2 2 4
Output
2
Explanation
Odd-indexed points form one component and even-indexed points another.