PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000008. Loại bỏ chu trình (Don’t be cycle)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Loại bỏ chu trình (Don’t be cycle)
Don’t be cycle
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a simple undirected graph with vertices and edges. You may remove edges. Find the minimum number of edges that must be removed so that the graph contains no cycles.
Input
The first line contains two integers . Each of the following lines contains two integers , describing an undirected edge. Vertices are numbered from to .
Output
Print the minimum number of edges to remove.
Subtasks
- Subtask 1 (20 points): ; ; ; ; no repeated edges.
- Subtask 2 (30 points): ; ; ; ; no repeated edges.
- Subtask 3 (50 points): ; ; ; ; no repeated edges.
Examples
Input
6 7
1 2
1 3
2 3
4 2
6 5
4 6
4 5
Output
2
Explanation
Two independent cycles each require one removed edge, so the answer is 2.