#K88312. Bipartite Graph Check

    ID: 37281 Type: Default 1000ms 256MiB

Bipartite Graph Check

Bipartite Graph Check

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 such that no edge connects vertices of the same set. In other words, it is possible to color the graph using two colors in such a way that no two adjacent vertices share the same color.

Input Format: The first line contains two integers n and m — the number of vertices and the number of edges. The following m lines each contain two integers u and v denoting that there is an edge between vertices u and v.

Output Format: Print "YES" if the graph is bipartite, otherwise print "NO".

inputFormat

The input is given via standard input. The first line contains two integers n and m, where n is the number of vertices and m is the number of edges. The next m lines each contain two space-separated integers u and v, indicating an undirected edge between vertices u and v.

outputFormat

Output a single line to standard output: "YES" if the graph is bipartite, otherwise "NO".## sample

3 3
1 2
1 3
2 3
NO