Check if the Graph is Bipartite
A graph is considered bipartite if it’s possible to colorize it with two colors such that no two adjacent vertices have the same color.
Determining if a graph is bipartite can help identify specific structures and properties, enabling efficient problem-solving in domains such as scheduling, resource allocation, and conflict resolution. Bipartite graphs also allow for simpler algorithms and optimizations in tasks like maximum matching and graph coloring.
You are given an undirected graph with
eedges. You should check if the graph is bipartite or not.
The first line of the input contains two integers
v(1 ≤ v ≤ 100 000) and
e(1 ≤ e ≤ 100 000).
elines contain pairs of integers
v2(1 ≤ v1, v2 ≤ v) which means that the vertex
v1is connected to the vertex
v2and vice versa.
The program should print
Yesif the given graph is bipartite and
2 1 2 1
3 2 2 1 1 3
3 3 1 2 1 3 2 3
Time limit: 1 seconds
Memory limit: 512 MB
Output limit: 1 MB