CF62D.Wormhouse
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Arnie the Worm has finished eating an apple house yet again and decided to move. He made up his mind on the plan, the way the rooms are located and how they are joined by corridors. He numbered all the rooms from 1 to n. All the corridors are bidirectional.
Arnie wants the new house to look just like the previous one. That is, it should have exactly n rooms and, if a corridor from room i to room j existed in the old house, it should be built in the new one.
We know that during the house constructing process Arnie starts to eat an apple starting from some room and only stops when he eats his way through all the corridors and returns to the starting room. It is also known that Arnie eats without stopping. That is, until Arnie finishes constructing the house, he is busy every moment of his time gnawing a new corridor. Arnie doesn't move along the already built corridors.
However, gnawing out corridors in one and the same order any time you change a house is a very difficult activity. That's why Arnie, knowing the order in which the corridors were located in the previous house, wants to gnaw corridors in another order. It is represented as a list of rooms in the order in which they should be visited. The new list should be lexicographically smallest, but it also should be strictly lexicographically greater than the previous one. Help the worm.
阿尼蠕虫又一次吃完了苹果屋,决定搬家。他已规划好了新居的布局:房间的分布方式以及房间之间走廊的连接方式。他将所有房间从 1 到 n 编号。所有走廊均为双向通道。
阿尼希望新居与旧居完全一致:即必须恰好有 n 个房间,且若旧居中存在一条连接房间 i 与房间 j 的走廊,则新居中也必须修建这样一条走廊。
我们已知,在建造房屋的过程中,阿尼从某个房间出发开始啃食苹果,并持续啃食,直至遍历所有走廊后返回起始房间为止。此外,阿尼全程不停歇地啃食——即在房屋建造完成前,他每一时刻都在啃出一条新的走廊;他不会在已建好的走廊上移动。
然而,每次更换房屋时都以完全相同的顺序啃出走廊,是一项极其困难的任务。因此,阿尼在已知旧居中走廊建成顺序的前提下,希望在新居中以另一种顺序啃出走廊。该顺序用一个房间序列来表示,即应依次访问的房间编号序列。新序列需满足:在所有可行序列中字典序最小,但又必须严格大于旧序列(按字典序比较)。请帮助这条蠕虫!
输入格式
The first line contains two integers n and m (3 ≤ n ≤ 100, 3 ≤ m ≤ 2000). It is the number of rooms and corridors in Arnie's house correspondingly. The next line contains m + 1 positive integers that do not exceed n. They are the description of Arnie's old path represented as a list of rooms he visited during the gnawing. It is guaranteed that the last number in the list coincides with the first one.
The first room described in the list is the main entrance, that's why Arnie should begin gnawing from it.
You may assume that there is no room which is connected to itself and there is at most one corridor between any pair of rooms. However, it is possible to find some isolated rooms which are disconnected from others.
第一行包含两个整数 n 和 m(3≤n≤100,3≤m≤2000),分别表示阿尼(Arnie)住宅中的房间数和走廊数。
下一行包含 m+1 个正整数,均不超过 n,它们描述了阿尼的旧路径,即他在啃咬过程中所访问的房间序列。保证该序列的最后一个数与第一个数相同。
序列中描述的第一个房间是主入口,因此阿尼必须从该房间开始啃咬。
你可以假设:不存在连接自身的房间,且任意两个房间之间至多只有一条走廊。但可能存在一些与其他房间均不连通的孤立房间。
输出格式
Print m + 1 positive integers that do not exceed n. Those numbers are the description of the new path, according to which Arnie should gnaw out his new house. If it is impossible to find new path you should print out No solution. The first number in your answer should be equal to the last one. Also it should be equal to the main entrance.
输出 m + 1 个不超过 n 的正整数,它们按顺序描述 Arnie 应该据此啃出新居的新路径。若无法找到这样的新路径,则输出 No solution。你答案中的第一个数必须等于最后一个数,且该数应等于主入口。
输入输出样例
输入#1
3 3 1 2 3 1
输出#1
1 3 2 1
输入#2
3 3 1 3 2 1
输出#2
No solution
输入解题思路,AI测评打分。不知道怎么写?