Bipartite Check

View as PDF

Submit solution


Points: 100
Time limit: 1.0s
PyPy 3 2.0s
Python 3 2.0s
Memory limit: 500M

Problem type

You are given an undirected graph with n vertices and m edges. The graph may be disconnected.

Determine whether every connected component can be colored using two colors so that every edge joins two vertices of different colors.

Input

The first line contains two integers n and m.

The next m lines each contain two integers a and b, meaning there is an undirected edge between vertices a and b.

Vertices are numbered from 1 to n.

Output

Print YES if the graph is bipartite. Otherwise, print NO.

Constraints

  • 1 \le n \le 200000
  • 0 \le m \le 300000
  • 1 \le a, b \le n

Example 1

Input
4 4
1 2
2 3
3 4
4 1
Output
YES
Explanation

The graph is a cycle of even length, so alternating the two colors around the cycle works.

Example 2

Input
3 3
1 2
2 3
3 1
Output
NO
Explanation

The graph is a triangle, so two adjacent vertices must eventually receive the same color.


Comments

There are no comments at the moment.