302353: CF453C. Little Pony and Summer Sun Celebration

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

Description

Little Pony and Summer Sun Celebration

题意翻译

给一个无向图,n个点m条边,给定一个01序列,如果a[i]=1,要求走到这个点奇数次,否则,要求走到这个点偶数次,请你任选起点,输出满足要求的经过点的序列和序列长度,序列长度不能超过4n

题目描述

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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF453C/076e2d37b9cb7b6614410629f2bfd3bd32464a7e.png)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 $ 4n $ places.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 2<=n<=10^{5}; 0<=m<=10^{5} $ ) — 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.

输出格式


Output the number of visited places $ k $ in the first line ( $ 0<=k<=4n $ ). 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.

输入输出样例

输入样例 #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

Input

题意翻译

给一个无向图,$n$ 个点 $m$ 条边,给定一个 $01$ 序列,如果 $a_i=1$,要求走到这个点奇数次,否则,要求走到这个点偶数次,请你任选起点,输出满足要求的经过点的序列和序列长度。序列长度不能超过 $4n$。

加入题单

上一题 下一题 算法标签: