There are
Of course, such a large project must take community needs into account. As such, the colouring of the roads must ensure that there is at least one path between Arid Alice's house
Either determine that no valid colouring exists, or find any valid colouring that
- Minimizes the total number of colours used (because paint is expensive).
- Ensures that the length of the shortest non-colourful path from
to is the minimum possible over all valid colourings.
Constraints
Each road connects two different houses, and no two roads connect the same pair of houses.
Subtask 1 [4/15]
In this subtask, you will get 2/15 points if you correctly determine whether a valid colouring exists in all test cases.
Subtask 2 [11/15]
No additional constraints.
In this subtask,
- You will get 3/15 points if you correctly determine whether a valid colouring exists in all test cases.
- You will get an additional 3/15 points if for all cases where a valid colouring exists, you output a valid colouring that minimizes the total number of colours, but the length of the shortest non-colourful path from
to is not the minimum possible over all valid colourings.
Input Specification
The first line contains
The next
The last line contains
Output Specification
If no valid colouring exists, output
Otherwise, output
Then, on the
Note that a solution which does not heed the output format provided above will not be rewarded with any points.
Sample Input 1
7 7
1 2
3 1
4 5
7 3
6 5
1 4
3 6
2 7 6 4
Sample Output 1
2
1
1
2
1
1
1
2
Explanation for Sample 1
The colouring of the roads is shown in the diagram above. It can be verified that there is a non-colourful path from
Sample Input 2
4 3
1 2
2 3
3 4
1 2 3 4
Sample Output 2
-1
Comments