Problem A
Colourful Graph
Consider an undirected graph on
You are given two
Formally, you are looking for a sequence of
-
; or -
where is an edge in the graph
The input graph is guaranteed to be connected and has no
self loops. Determine whether it is possible to construct such
a sequence, and output one if there is any. The sequence need
not be the shortest as long as it uses at most
For example, suppose you need to start with the initial colouring on the left and end up with the final colouring on the right:
![\includegraphics[width=.5\textwidth ]{startend}](/problems/colourful/file/statement/en/img-0001.png)
One solution is as follows:
![\includegraphics[width=.5\textwidth ]{transitions}](/problems/colourful/file/statement/en/img-0002.png)
Input
The first line of input contains three integers
The input graph is connected. There are no self loops or multiple edges.
Output
Output Impossible if there is no
such sequence. Otherwise, output one or more lines describing a
sequence of colouring
You can use at most
Sample Input 1 | Sample Output 1 |
---|---|
6 6 2 0 1 0 1 1 1 1 0 0 0 1 0 1 2 2 3 3 5 5 4 4 6 6 5 |
0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 0 |
Sample Input 2 | Sample Output 2 |
---|---|
1 0 2 0 1 |
Impossible |