Bipartite graphs · Compiler

Bipartite graphs

Decide whether the entire two-way network can be colored with two colors so that every edge joins vertices of different colors. Include every connected component in the check.

Input
The first line contains n m. Vertices are numbered 0 through n-1 (1 <= n <= 50, 0 <= m <= 200). Each of the next m lines contains u v for an edge joining u and v in both directions. Endpoints differ and each unordered pair occurs at most once.
Output
Print YES if such a coloring exists, or NO otherwise.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…