#K36847. Bipartite Graph Verification

    ID: 25845 Type: Default 1000ms 256MiB

Bipartite Graph Verification

Bipartite Graph Verification

You are given an undirected graph with N nodes and M edges. Your task is to determine whether the graph is bipartite or not.

A graph is bipartite if its set of vertices can be divided into two disjoint subsets such that no two vertices within the same subset are adjacent. In mathematical notation, a graph G = (V, E) is bipartite if there exists a partition V = V1 \cup V2 such that for every edge (u, v) ∈ E, either u ∈ V1 and v ∈ V2 or u ∈ V2 and v ∈ V1.

If the graph is bipartite, output 1; otherwise, output 0.

Note: The graph might be disconnected. You must check each connected component.

inputFormat

The first line of input contains two integers N and M representing the number of nodes and the number of edges, respectively.

The next M lines each contain two integers u and v indicating an undirected edge between nodes u and v.

It is guaranteed that 1 ≤ u, v ≤ N.

outputFormat

Output a single integer: 1 if the graph is bipartite, otherwise 0. The output should be printed to stdout.

## sample
4 4
1 2
2 3
3 4
4 1
1