

The first line of input contains an integer ‘T’, the number of test cases.
The first line of each test case contains two single space-separated integers, ‘N’ and ‘E’, representing the sum of electrons and protons and the number of interconnections, respectively.
The next ‘E’ lines will denote the interconnections between protons and electrons defined by two single space-separated integers ‘X' and 'Y', which signifies an interconnection between ‘X’ and ‘Y’.
For each test case, return a single integer ‘1’ if they can be separated, else print ‘0’.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 2*10^3
1 <= E <= 10^5
1 <= X, Y <= N
Time Limit : 1 sec
The basic idea is to check whether the given interconnections are a bipartite graph or not. A bipartite graph is a graph in which the graph’s vertices can be divided into two independent sets, ‘U’ and ‘V’, such that for every edge (u, v), either u belongs to set ‘U’ and v belongs to set ‘V’ or vice-versa. They shouldn’t belong to the same set. A bipartite graph can be colored so that only two colors in total would be used, where the neighbor vertices have different colors. Therefore we can assign colors to each vertex, and if at any point neighboring vertices have the same color, we return false.
Here is the algorithm :
BFS(‘GRAPH’, ‘S’, ‘VISITED’, ‘COLOR’)
The approach is very similar to approach 1. We will be using DFS to check for a bipartite graph.
DFS(‘GRAPH’, ‘U’, ‘VISITED’, ‘COLOR’)