#abc292d. D - Unicyclic Components

D - Unicyclic Components

Score : 400400 points

问题描述

给定一个无向图,其中包含 NN 个顶点,编号为 11NN,以及 MM 条边,编号为 11MM。第 ii 条边连接顶点 uiu_i 和顶点 viv_i

判断图中的每个连通分量是否满足以下条件:

  • 连通分量中的顶点数和边数相等。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given an undirected graph with NN vertices numbered 11 to NN and MM edges numbered 11 to MM. Edge ii connects vertex uiu_i and vertex viv_i.

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

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0M2×1050 \leq M \leq 2 \times 10^5
  • 1uiviN1 \leq u_i \leq v_i \leq N
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM

u1u_1 v1v_1

\vdots

uMu_M vMv_M

Output

If every connected component satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 3
2 3
1 1
2 3

Sample Output 1

Yes

The graph has a connected component formed from just vertex 11, and another formed from vertices 22 and 33.
The former has one edge (edge 22), and the latter has two edges (edges 11 and 33), satisfying the condition.

Sample Input 2

5 5
1 2
2 3
3 4
3 5
1 5

Sample Output 2

Yes

Sample Input 3

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

Sample Output 3

No

update @ 2024/3/10 12:10:53