Score : $600$ points
You are given a simple connected undirected graph with $N$ vertices and $M$ edges. (A graph is said to be simple if it has no multi-edges and no self-loops.)
For $i = 1, 2, \ldots, M$, the $i$-th edge connects Vertex $u_i$ and Vertex $v_i$.
A sequence $(A_1, A_2, \ldots, A_k)$ is said to be a path of length $k$ if both of the following two conditions are satisfied:
An empty sequence is regarded as a path of length $0$.
You are given a sting $S = s_1s_2\ldots s_N$ of length $N$ consisting of $0$ and $1$. A path $A = (A_1, A_2, \ldots, A_k)$ is said to be a good path with respect to $S$ if the following conditions are satisfied:
Under the Constraints of this problem, it can be proved that there is at least one good path with respect to $S$ of length at most $4N$. Print a good path with respect to $S$ of length at most $4N$.
Input is given from Standard Input in the following format:
$N$ $M$ $u_1$ $v_1$ $u_2$ $v_2$ $\vdots$ $u_M$ $v_M$ $S$
Print a good path with respect to $S$ of length at most $4N$ in the following format. Specifically, the first line should contain the length $K$ of the path, and the second line should contain the elements of the path, with spaces in between.
$K$ $A_1$ $A_2$ $\ldots$ $A_K$
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 $(2, 5, 6, 5, 6, 3, 1, 3, 6)$ has a length no greater than $4N$, and
so it is a good path with respect to $S = 110001$.
3 3 3 1 3 2 1 2 000
0
An empty path $()$ is a good path with respect to $S = 000000$. Alternatively, paths like $(1, 2, 3, 1, 2, 3)$ are also accepted.