atcoder#ABC292D. [ABC292D] Unicyclic Components
[ABC292D] Unicyclic Components
Score : points
Problem Statement
You are given an undirected graph with vertices numbered to and edges numbered to . Edge connects vertex and vertex .
Determine whether every connected component in this graph satisfies the following condition.
- The connected component has the same number of vertices and edges.
Notes
An undirected graph is a graph with edges without direction. A subgraph of a graph is a graph formed from a subset of vertices and edges of that graph. A graph is connected when one can travel between every pair of vertices in the graph via edges. A connected component is a connected subgraph that is not part of any larger connected subgraph.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
If every connected component satisfies the condition, print Yes
; otherwise, print No
.
3 3
2 3
1 1
2 3
Yes
The graph has a connected component formed from just vertex , and another formed from vertices and . The former has one edge (edge ), and the latter has two edges (edges and ), satisfying the condition.
5 5
1 2
2 3
3 4
3 5
1 5
Yes
13 16
7 9
7 11
3 8
1 13
11 11
6 11
8 13
2 11
3 3
8 12
9 11
1 11
5 13
3 12
6 9
1 10
No