#K63772. Bipartite Graph Check

    ID: 31828 Type: Default 1000ms 256MiB

Bipartite Graph Check

Bipartite Graph Check

You are given an undirected graph \(G=(V,E)\) with \(n\) vertices and \(m\) edges. The graph might be disconnected. Your task is to determine whether the graph is bipartite; that is, whether its vertices can be colored using two colors such that no two adjacent vertices share the same color.

If the graph is bipartite, output YES; otherwise, output NO.

inputFormat

The input is given via standard input and has the following format:

  • The first line contains two integers \(n\) and \(m\), where \(n\) is the number of vertices and \(m\) is the number of edges.
  • Each of the following \(m\) lines contains two integers \(u\) and \(v\), representing an undirected edge between vertices \(u\) and \(v\).

outputFormat

Output a single line: YES if the graph is bipartite, and NO otherwise.

## sample
3 2
1 2
2 3
YES