Some pairs of players refuse to be in the same team. Can everybody be split into two teams? Write TwoTeams. Read n m and m pairs u v that must be separated. Colour the graph with BFS: the first vertex of each component (lowest number) goes to team 1, and every neighbour of a vertex goes to the opposite team. If two neighbours end up with the same colour, it is impossible.
Print the two teams, or Impossible: … and the reason.
For the input
6 5
0 1
1 2
2 3
3 4
4 5
the program prints
Team 1: [0, 2, 4]
Team 2: [1, 3, 5]
The graph is bipartite