atcoder#ABC244G. [ABC244G] Construct Good Path
[ABC244G] Construct Good Path
Score : points
Problem Statement
You are given a simple connected undirected graph with vertices and edges. (A graph is said to be simple if it has no multi-edges and no self-loops.) For , the -th edge connects Vertex and Vertex .
A sequence is said to be a path of length if both of the following two conditions are satisfied:
- For all , it holds that .
- For all , Vertex and Vertex are directly connected with an edge.
An empty sequence is regarded as a path of length .
You are given a sting of length consisting of and . A path is said to be a good path with respect to if the following conditions are satisfied:
- For all , it holds that:- if , then has even number of 's.
- if , then has odd number of 's.
Under the Constraints of this problem, it can be proved that there is at least one good path with respect to of length at most . Print a good path with respect to of length at most .
Constraints
- $N-1 \leq M \leq \min\lbrace 2 \times 10^5, \frac{N(N-1)}{2}\rbrace$
- The given graph is simple and connected.
- , and are integers.
- is a string of length consisting of and .
Input
Input is given from Standard Input in the following format:
Output
Print a good path with respect to of length at most in the following format. Specifically, the first line should contain the length of the path, and the second line should contain the elements of the path, with spaces in between.
6 6
6 3
2 5
4 2
1 3
6 5
3 2
110001
9
2 5 6 5 6 3 1 3 6
The path has a length no greater than , and
- it has odd number () of
- it has odd number () of
- it has even number () of
- it has even number () of
- it has even number () of
- it has odd number () of
so it is a good path with respect to .
3 3
3 1
3 2
1 2
000
0
An empty path is a good path with respect to . Alternatively, paths like are also accepted.