Two Teams
Can the people be split into two teams so that every link joins members of different teams (is the graph bipartite)?
Input: the first line has N and M; each of the next M lines has an edge u v (1-based).
Output: YES or NO.
Constraints:
- 1 ≤ N ≤ 104
- 0 ≤ M ≤ 2×104
- multiple edges and self-loops may appear
Sample Tests
Input 1
4 4 1 2 2 3 3 4 4 1
Output 1
YES
Input 2
3 3 1 2 2 3 3 1
Output 2
NO
Discussion (opens after you solve — no spoilers before)
No comments yet.