#K16016. Bipartite Graph Check

    ID: 24485 Type: Default 1000ms 256MiB

Bipartite Graph Check

Bipartite Graph Check

Given an undirected graph with (V) vertices and (E) edges, determine whether the graph is bipartite. A graph is bipartite if its vertex set can be partitioned into two disjoint sets such that every edge connects a vertex from one set to a vertex in the other set. In other words, it is possible to color the vertices using two colors (say 0 and 1) so that for every edge ((u, v)), we have (color[u] \neq color[v]). A common approach is to use Breadth-First Search (BFS) starting from an uncolored vertex and assigning alternating colors to adjacent vertices.

Input and output are handled via standard input (stdin) and standard output (stdout).

inputFormat

The first line contains two integers (V) and (E) representing the number of vertices and edges respectively. Each of the following (E) lines contains two integers (u) and (v) (0-indexed) indicating an undirected edge between vertices (u) and (v).

outputFormat

Output a single line containing either 'YES' if the graph is bipartite, or 'NO' otherwise.## sample

4 4
0 1
0 3
1 2
2 3
YES