PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000018. Các thành phần hình vòng (Cyclic Components)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Các thành phần hình vòng (Cyclic Components)
Cyclic Components
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a simple undirected graph with vertices and edges. A connected component is called a cyclic component if its vertices and edges form exactly one simple cycle of length at least three.
Count the cyclic components of the graph.
Input
The first line contains two integers . Each of the next lines contains two integers , describing an undirected edge. Vertices are numbered from to .
Output
Print the number of cyclic connected components.
Subtasks
- Subtask 1 (20 points): ; ; ; ; no repeated edges.
- Subtask 2 (30 points): ; ; ; ; no repeated edges.
- Subtask 3 (50 points): ; ; ; ; no repeated edges.
Examples
Input
5 4
1 2
3 4
5 4
3 5
Output
1
Explanation
Component {1,2} is just one edge, while {3,4,5} forms a 3-cycle, giving 1.