CF453C.Little Pony and Summer Sun Celebration

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn her mentor Princess Celestia, but the princess ignored her and sent her to Ponyville to check on the preparations for the celebration.

Twilight Sparkle wanted to track the path of Nightmare Moon. Unfortunately, she didn't know the exact path. What she knew is the parity of the number of times that each place Nightmare Moon visited. Can you help Twilight Sparkle to restore any path that is consistent with this information?

Ponyville can be represented as an undirected graph (vertices are places, edges are roads between places) without self-loops and multi-edges. The path can start and end at any place (also it can be empty). Each place can be visited multiple times. The path must not visit more than 4_n_ places.

暮光闪闪得知,被囚禁在月球上长达一千年的邪恶梦魇之月将在即将到来的夏日阳光庆典期间重返世间。她试图警告导师塞拉斯蒂娅公主,但公主却置若罔闻,并将她派往小马谷,去检查庆典的筹备工作。

暮光闪闪希望追踪梦魇之月的行进路径。不幸的是,她并不知道其确切路径,仅知晓梦魇之月访问每个地点的次数的奇偶性。你能帮助暮光闪闪还原出一条与该奇偶性信息一致的路径吗?

小马谷可建模为一个无向图(顶点表示地点,边表示地点之间的道路),该图不含自环和重边。路径可在任意地点开始与结束(亦可为空路径)。每个地点可被多次访问。路径所经地点总数不得超过 4n4n 个。

输入格式

The first line contains two integers n and m (2 ≤ n ≤ 105; 0 ≤ m ≤ 105) — the number of places and the number of roads in Ponyville. Each of the following m lines contains two integers u__i, v__i (1 ≤ u__i, v__i ≤ n; u__i ≠ v__i), these integers describe a road between places u__i and v__i.

The next line contains n integers: _x_1, _x_2, ..., x__n (0 ≤ x__i ≤ 1) — the parity of the number of times that each place must be visited. If x__i = 0, then the i-th place must be visited even number of times, else it must be visited odd number of times.

第一行包含两个整数 nn 和 mm(2≤n≤1052 \leq n \leq 10^5;0≤m≤1050 \leq m \leq 10^5)—— 分别表示小马谷中的地点数量和道路数量。接下来的 mm 行,每行包含两个整数 ui, viu_i,\,v_i(1≤ui, vi≤n1 \leq u_i,\,v_i \leq n;ui≠viu_i \neq v_i),表示在地点 uiu_i 与 viv_i 之间存在一条道路。

下一行包含 nn 个整数:x1, x2, …, xnx_1,\,x_2,\,\dots,\,x_n(0≤xi≤10 \leq x_i \leq 1)—— 表示每个地点必须被访问次数的奇偶性。若 xi=0x_i = 0,则第 ii 个地点必须被访问偶数次;否则(即 xi=1x_i = 1)必须被访问奇数次。

输出格式

Output the number of visited places k in the first line (0 ≤ k ≤ 4_n_). Then output k integers — the numbers of places in the order of path. If x__i = 0, then the i-th place must appear in the path even number of times, else i-th place must appear in the path odd number of times. Note, that given road system has no self-loops, therefore any two neighbouring places in the path must be distinct.

If there is no required path, output -1. If there multiple possible paths, you can output any of them.

第一行输出访问过的地点数量 kk(0 ≤ k ≤ 4n0 \le k \le 4n)。随后一行输出 kk 个整数——按路径顺序排列的各地点编号。若 xi=0x_i = 0,则第 ii 个地点在路径中必须出现偶数次;否则(即 xi≠0x_i \ne 0),第 ii 个地点在路径中必须出现奇数次。注意:给定的道路系统中没有自环,因此路径中任意两个相邻地点必须互不相同。

若不存在满足条件的路径,则输出 −1-1。若存在多条满足条件的路径,输出任意一条即可。

输入输出样例

  • 输入#1

    3 2
    1 2
    2 3
    1 1 1

    输出#1

    3
    1 2 3
  • 输入#2

    5 7
    1 2
    1 3
    1 4
    1 5
    3 4
    3 5
    4 5
    0 1 0 1 0

    输出#2

    10
    2 1 3 4 5 4 5 4 3 1
  • 输入#3

    2 0
    0 0

    输出#3

    0

输入解题思路,AI测评打分。不知道怎么写?

首页