102446: [AtCoder]ABC244 G - Construct Good Path

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

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:

  • For all $i = 1, 2, \dots, k$, it holds that $1 \leq A_i \leq N$.
  • For all $i = 1, 2, \ldots, k-1$, Vertex $A_i$ and Vertex $A_{i+1}$ are directly connected with an edge.

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:

  • For all $i = 1, 2, \ldots, N$, it holds that:
    • if $s_i = 0$, then $A$ has even number of $i$'s.
    • if $s_i = 1$, then $A$ has odd number of $i$'s.

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$.

Constraints

  • $2 \leq N \leq 10^5$
  • $N-1 \leq M \leq \min\lbrace 2 \times 10^5, \frac{N(N-1)}{2}\rbrace$
  • $1 \leq u_i, v_i \leq N$
  • The given graph is simple and connected.
  • $N, M, u_i$, and $v_i$ are integers.
  • $S$ is a string of length $N$ consisting of $0$ and $1$.

Input

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$

Output

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$

Sample Input 1

6 6
6 3
2 5
4 2
1 3
6 5
3 2
110001

Sample Output 1

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

  • it has odd number ($1$) of $1$
  • it has odd number ($1$) of $2$
  • it has even number ($2$) of $3$
  • it has even number ($0$) of $4$
  • it has even number ($2$) of $5$
  • it has odd number ($3$) of $6$

so it is a good path with respect to $S = 110001$.


Sample Input 2

3 3
3 1
3 2
1 2
000

Sample Output 2

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.

Input

题意翻译

给定一个 $N$ 个点 $M$ 条边的无向简单连通图,以及一个长为 $N$ 的 01 串 $s_i$。求一条长度不超过 $4N$ 的路径(可重复经过点或边,不必非空)$(A_i)_m$ 使得 $i$ 号结点在路径序列中出现次数模 $2$ 余数为 $s_i$。多种答案可以输出任意一种合法方案。 保证 $2\le N\le 10^5$,$N-1\le M\le\max\{2\times 10^5,\frac{N(N-1)}2\}$。 保证在上述条件下答案一定存在。

Output

分数:600分

问题描述

给你一个包含 $N$ 个顶点和 $M$ 条边的简单连通无向图。 (如果一个图没有多边和自环,那么就称它为简单图。)
对于 $i = 1, 2, \ldots, M$,第 $i$ 条边连接顶点 $u_i$ 和顶点 $v_i$。

一个序列 $(A_1, A_2, \ldots, A_k)$ 称为长度为 $k$ 的 路径,如果满足以下两个条件:

  • 对于所有 $i = 1, 2, \dots, k$,都有 $1 \leq A_i \leq N$。
  • 对于所有 $i = 1, 2, \ldots, k-1$,顶点 $A_i$ 和顶点 $A_{i+1}$ 之间有一条边相连。

空序列被视为长度为 $0$ 的路径。

给你一个由 $0$ 和 $1$ 组成的长度为 $N$ 的字符串 $S = s_1s_2\ldots s_N$。一个路径 $A = (A_1, A_2, \ldots, A_k)$ 称为相对于 $S$ 的 好路径,如果满足以下条件:

  • 对于所有 $i = 1, 2, \ldots, N$,都有:
    • 如果 $s_i = 0$,那么 $A$ 包含偶数个 $i$。
    • 如果 $s_i = 1$,那么 $A$ 包含奇数个 $i$。

在本问题的约束下,可以证明存在至少一条相对于 $S$ 的长度不超过 $4N$ 的好路径。输出一条相对于 $S$ 的长度不超过 $4N$ 的好路径。

约束条件

  • $2 \leq N \leq 10^5$
  • $N-1 \leq M \leq \min\lbrace 2 \times 10^5, \frac{N(N-1)}{2}\rbrace$
  • $1 \leq u_i, v_i \leq N$
  • 给定的图是简单且连通的。
  • $N, M, u_i$, 和 $v_i$ 都是整数。
  • $S$ 是一个由 $0$ 和 $1$ 组成的长度为 $N$ 的字符串。

输入

从标准输入按照以下格式获取输入:

$N$ $M$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_M$ $v_M$
$S$

输出

按照以下格式输出一条相对于 $S$ 的长度不超过 $4N$ 的好路径。具体来说,第一行应该包含路径的长度 $K$,第二行应该包含路径中的元素,元素之间用空格隔开。

$K$
$A_1$ $A_2$ $\ldots$ $A_K$

样例输入 1

6 6
6 3
2 5
4 2
1 3
6 5
3 2
110001

样例输出 1

9
2 5 6 5 6 3 1 3 6

路径 $(2, 5, 6, 5, 6, 3, 1, 3, 6)$ 的长度不超过 $4N$,并且

  • 它包含奇数个 ($1$) 的 $1$
  • 它包含奇数个 ($1$) 的 $2$
  • 它包含偶数个 ($2$) 的 $3$
  • 它包含偶数个 ($0$) 的 $4$
  • 它包含偶数个 ($2$) 的 $5$
  • 它包含奇数个 ($3$) 的 $6$

所以它是一个相对于 $S = 110001$ 的好路径。


样例输入 2

3 3
3 1
3 2
1 2
000

样例输出 2

0

空路径 $()$ 是一个相对于 $S = 000000$ 的好路径。此外,像 $(1, 2, 3, 1, 2, 3)$ 这样的路径也被接受。

加入题单

算法标签: