#C5755. Bipartite Graph Checker

    ID: 49439 Type: Default 1000ms 256MiB

Bipartite Graph Checker

Bipartite Graph Checker

You are given an undirected graph with n vertices and m edges. Your task is to determine whether the graph is bipartite. A graph is bipartite if its vertices can be divided into two disjoint sets \(U\) and \(V\) such that every edge connects a vertex in \(U\) to one in \(V\).

In other words, it must be possible to assign one of two different colors to each vertex in such a way that no two adjacent vertices share the same color.

The input consists of multiple test cases. For each test case, you will be given the number of vertices and edges followed by the list of edges. For each test case, output YES if the graph is bipartite and NO otherwise.

inputFormat

The input is read from stdin and has the following format:

T
n1 m1
u1 v1
...
um1 vm1
...
nT mT
u1 v1
...
umT vmT

Here, T is the number of test cases. For each test case, the first line contains two integers n and m, representing the number of vertices and edges respectively. Then follow m lines, each containing two integers u and v which represent an edge between vertices u and v.

outputFormat

For each test case, output a single line containing YES if the graph is bipartite or NO if it is not. The output should be written to stdout.

## sample
1
3 3
1 2
2 3
3 1
NO

</p>