PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000013. Đồ thị có phải đường đi? (Path Graph?)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đồ thị có phải đường đi? (Path Graph?)
Path Graph?
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a simple undirected graph with vertices and edges. It is a path graph if its vertices can be ordered as so that its edges are exactly . Determine whether the given graph is a path graph.
Input
The first line contains two integers . Each of the next lines contains two integers , denoting an undirected edge. Vertices are numbered from to .
Output
Print Yes if the graph is a path graph and No otherwise.
Subtasks
- Subtask 1 (20 points): ; ; ; ; no repeated edges.
- Subtask 2 (30 points): ; ; ; ; no repeated edges.
- Subtask 3 (50 points): ; ; ; ; no repeated edges.
Examples
Input
4 3
1 3
4 2
3 2
Output
Yes
Explanation
The edges form the chain 1–3–2–4, with all vertices on one simple path.