You are given a cactus with
Formally, let a path be a list of
Constraints
For this problem, you will NOT be required to pass all the samples in order to receive points. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.
Subtask | Points | Additional Constraints | |
---|---|---|---|
None | |||
For each colour, there are at most 2 vertices of that colour | |||
None | |||
None |
For all subtasks:
The graph is a cactus.
There will be no self loops (an edge from a vertex to itself) and no multiple edges between any two vertices.
Input Specification
The first line contains 2 integers,
The next line contains
The next
Output Specification
This problem is graded with an identical
checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n
character and that there are no trailing spaces.
Output a single line containing -1
instead.
Sample Input 1
6 6
1 3 6 6 6 1
1 2
2 3
3 1
1 4
2 5
3 6
Sample Output 1
2 -1 -1 -1 -1 2
Sample Explanation 1
The shortest path between any two vertices of colour
The shortest path between any two vertices of colour
All other colours have less than two vertices.
Sample Input 2
5 4
2 5 4 5 4
4 2
5 2
4 1
3 4
Sample Output 2
-1 -1 -1 3 1
Sample Explanation 2
The shortest path between any two vertices of colour
The shortest path between any two vertices of colour
All other colours have less than two vertices.
Comments