#C1668. Bipartite Graph Coloring
Bipartite Graph Coloring
Bipartite Graph Coloring
Given T graphs, each graph consists of n vertices numbered from 1 to n and m edges. Determine whether each graph is bipartite, i.e., whether its vertices can be colored using exactly two colors such that no two adjacent vertices share the same color. In other words, a graph (G=(V,E)) is bipartite if there exists a partition (V = V_1 \cup V_2) with (V_1 \cap V_2 = \emptyset) and for every edge ((u,v)\in E), we have (u\in V_1) and (v\in V_2) (or vice versa). Note that the input graphs may be disconnected.
For each test case, output "YES" if the graph is bipartite and "NO" otherwise.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (T) representing the number of test cases. For each test case, the first line contains two integers (n) and (m), indicating the number of vertices and edges respectively. This is followed by (m) lines, each containing two integers (u) and (v) which represent an undirected edge between vertices (u) and (v).
outputFormat
For each test case, print a single line to standard output (stdout) containing either "YES" if the graph is bipartite, or "NO" if it is not.## sample
1
1 0
YES
</p>