CF1494F.Delete The Edges
省选/NOI-
通过率:0%
时间限制:8.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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?
给你一个由 n 个顶点和 m 条边构成的无向连通图。你的目标是摧毁该图中的所有边。
你可以任选一个顶点作为起点,并从该顶点出发沿边行走。当你沿一条边行走时,该边即被摧毁。显然,你无法沿已被摧毁的边行走。
在整段行走过程中,你最多可执行一次“模式切换”操作,且该操作只能在你位于某个顶点上时进行(不能在穿越边的过程中执行)。模式切换后,你所经过的边将按如下方式被删除:模式切换后的第一条边不被摧毁,第二条边被摧毁,第三条边不被摧毁,第四条边被摧毁,依此类推。你无法再切换回原始模式;若你不想执行该操作,也可以选择不执行。
你能否摧毁给定图中的所有边?
输入格式
The first line contains two integers n and m (2≤n≤3000; n−1≤m≤min(2n(n−1),3000)) — the numbef of vertices and the number of edges in the graph.
Then m lines follow, each containing two integers xi and yi (1≤xi,yi≤n; xi=yi) — the endpoints of the i-th edge.
These edges form a connected undirected graph without multiple edges.
第一行包含两个整数 n 和 m(2≤n≤3000;n−1≤m≤min(2n(n−1),3000)),分别表示图中顶点的数量和边的数量。
接下来是 m 行,每行包含两个整数 xi 和 yi(1≤xi,yi≤n;xi=yi),表示第 i 条边的两个端点。
这些边构成一个连通的无向图,且不含重边。
输出格式
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≤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.
如果无法摧毁所有边,则输出 0。
否则,按如下格式输出你的操作序列:首先输出 k —— 操作的次数(k≤2m+2);然后输出该序列本身,它由 k 个整数组成。第一个整数应为起始顶点的编号;接下来的每个整数应为遍历中下一个顶点的编号,或为 −1(表示执行模式切换)。你最多只能执行一次模式切换。
若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?