308291: CF1494F. Delete The Edges

Memory Limit:512 MB Time Limit:8 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Delete The Edges

题意翻译

### 题意 给定一个 $n$ 个顶点和 $m$ 条边组成的无向连通图。你的目标是破坏给定图形的所有边。 可以选择任何顶点作为起始顶点,开始沿边行走。当你走过一条边时,这条边会被破坏,不能走被破坏的边。 最多可以在某顶点执行进行一次模式切换,模式转换后,按以下方式删除经过的边:模式转换后第一条边不被破坏,第二条边被破坏,第三条边不被破坏,第四条边被破坏,依此类推。不能切换回原始模式,可以不执行此操作。 $n,m \le 3000, m\le \dfrac{n(n-1)}{2}$。 ### 输入格式 输入 $n,m$,然后依次输入每条边的两个顶点。 ### 输出格式 第一行一个操作次数 $k$。 第二行 $k$ 个整数,第一个整数为起始节点,依次输出下一个访问节点。如果进行模式切换,输出 $-1$,然后再输出后面的节点编号。要求 $k \le 2m+2$。 如果无法完成任务,输出 $0$。

题目描述

You are given an undirected connected graph consisting of $ n $ vertices and $ m $ edges. Your goal is to destroy all edges of the given graph. You may choose any vertex as the starting one and begin walking from it along the edges. When you walk along an edge, you destroy it. Obviously, you cannot walk along an edge if it is destroyed. You can perform the mode shift operation at most once during your walk, and this operation can only be performed when you are at some vertex (you cannot perform it while traversing an edge). After the mode shift, the edges you go through are deleted in the following way: the first edge after the mode shift is not destroyed, the second one is destroyed, the third one is not destroyed, the fourth one is destroyed, and so on. You cannot switch back to the original mode, and you don't have to perform this operation if you don't want to. Can you destroy all the edges of the given graph?

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 2 \le n \le 3000 $ ; $ n - 1 \le m \le \min(\frac{n(n-1)}{2}, 3000 $ )) — the numbef of vertices and the number of edges in the graph. Then $ m $ lines follow, each containing two integers $ x_i $ and $ y_i $ ( $ 1 \le x_i, y_i \le n $ ; $ x_i \ne y_i $ ) — the endpoints of the $ i $ -th edge. These edges form a connected undirected graph without multiple edges.

输出格式


If it's impossible to destroy all of the edges, print 0. Otherwise, print the sequence of your actions as follows. First, print $ k $ — the number of actions ( $ k \le 2m + 2 $ ). Then, print the sequence itself, consisting of $ k $ integers. The first integer should be the index of the starting vertex. Then, each of the next integers should be either the index of the next vertex in your traversal, or $ -1 $ if you use mode shift. You are allowed to use mode shift at most once. If there are multiple answers, print any of them.

输入输出样例

输入样例 #1

3 3
1 2
2 3
3 1

输出样例 #1

4
1 2 3 1

输入样例 #2

4 3
1 2
2 3
4 2

输出样例 #2

8
2 -1 1 2 3 2 4 2

输入样例 #3

5 5
1 2
2 3
3 1
2 4
2 5

输出样例 #3

9
2 3 1 2 -1 4 2 5 2

输入样例 #4

5 5
1 2
2 3
3 1
2 4
4 5

输出样例 #4

8
5 4 2 3 1 -1 2 1

输入样例 #5

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

输出样例 #5

0

Input

题意翻译

### 题意 给定一个 $n$ 个顶点和 $m$ 条边组成的无向连通图。你的目标是破坏给定图形的所有边。 可以选择任何顶点作为起始顶点,开始沿边行走。当你走过一条边时,这条边会被破坏,不能走被破坏的边。 最多可以在某顶点执行进行一次模式切换,模式转换后,按以下方式删除经过的边:模式转换后第一条边不被破坏,第二条边被破坏,第三条边不被破坏,第四条边被破坏,依此类推。不能切换回原始模式,可以不执行此操作。 $n,m \le 3000, m\le \dfrac{n(n-1)}{2}$。 ### 输入格式 输入 $n,m$,然后依次输入每条边的两个顶点。 ### 输出格式 第一行一个操作次数 $k$。 第二行 $k$ 个整数,第一个整数为起始节点,依次输出下一个访问节点。如果进行模式切换,输出 $-1$,然后再输出后面的节点编号。要求 $k \le 2m+2$。 如果无法完成任务,输出 $0$。

加入题单

算法标签: