#K13626. Bipartite Graph Check
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 vertices can be divided into two disjoint sets such that no two vertices within the same set are adjacent. Equivalently, a graph is bipartite if it does not contain an odd-length cycle.
You are given the number of vertices \(V\) and edges \(E\) followed by \(E\) pairs of integers, where each pair represents an undirected edge connecting two vertices. Vertices are labeled from 1 to \(V\). Use a BFS (Breadth First Search) based algorithm to color the graph and verify its bipartiteness.
inputFormat
The first line contains two integers \(V\) and \(E\), giving the number of vertices and edges respectively. Each of the following \(E\) lines contains two integers \(u\) and \(v\) representing an edge between vertices \(u\) and \(v\).
outputFormat
Output a single line containing either "YES" if the graph is bipartite or "NO" if it is not.
## sample5 5
1 2
2 3
3 4
4 5
5 1
NO