Loading repovive.com/problems/classics/30
Given an undirected graph with n vertices and m edges, determine if it is bipartite.
A graph is bipartite if its vertices can be divided into two disjoint sets such that every edge connects a vertex in one set to a vertex in the other set. Equivalently, a graph is bipartite if and only if it contains no odd-length cycle.
Output YES if the graph is bipartite, otherwise output NO.
YES or NO
4 3 1 2 2 3 3 4
For this input, the required output is YES.
YES
3 3 1 2 2 3 3 1
For this input, the required output is NO.
NO
4 2 1 2 3 4
For this input, the required output is YES.
YES