Bipartite graph - MarisaOJ: Marisa Online Judge

Bipartite graph

Time limit: 1000 ms
Memory limit: 256 MB
Given a undirected graph of $n$ vertices and $m$ edges. Determine whether or not this graph is a bipartite graph. A graph is bipartite if and only if you can color its vertices in 2 different colors such that no 2 adjacent vertices have the same color. ### Input - The first line contains 2 integers $n, m$. - The next $m$ lines, each line contains 2 integers $u, v$, there is an edge between $u$ and $v$. It is guaranteed that there is no loop. ### Output - Print `YES` if the given graph is bipartite, otherwise print `NO`. ### Constraints - $1 \le n, m \le 10^5$. - $1 \le u, v \le n$. ### Example Input: ``` 5 4 3 1 5 2 1 4 2 3 ``` Output: ``` YES ```