You are on page 1of 2

Instituto Politécnico Nacional

Centro de Investigación en Computación


Análisis y Diseño de Algoritmos

Testing Bipartiteness
1. Statement

A Bipartite Graph is a graph whose vertices can be divided into two independent sets, U and V such that
every edge (u, v) either connects a vertex from U to V or a vertex from V to U. In other words, for every
edge (u, v), either u belongs to U and v to V, or u belongs to V and v to U. We can also say that there is no
edge that connects vertices of same set.

Figure 1.- Example of a bipartite graph.

Given a connected graph G, find the two independent sets U and V.

2. Input

The input file contains one test case as described below. First line contains two space separated
integers V (1 ≤ V ≤ 100, the number of vertices in the graph) and E (1 ≤ E ≤ 100, the number of
edges in the graph).

3. Output

Output two list of integers denoting the vertices of set U and V, on a line by itself. Each list is arranged
from lowest to highest value (sorted ascending) and the lists are printed using the index of the first vertex.
If the graph is not a bipartite graph, print one line with the string EMPTY.

4. Sample Input

7 11
1 2
1 4
1 5
Instituto Politécnico Nacional
Centro de Investigación en Computación
Análisis y Diseño de Algoritmos

1 7
2 3
2 6
3 4
3 5
3 7
5 6
6 7

5. Sample Output

1 3 6
2 4 5 7

==================== END OF DOCUMENT ====================

You might also like