CF925D.Aztec Catacombs
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Indiana Jones found ancient Aztec catacombs containing a golden idol. The catacombs consists of n caves. Each pair of caves is connected with a two-way corridor that can be opened or closed. The entrance to the catacombs is in the cave 1 , the idol and the exit are in the cave n .
When Indiana goes from a cave x to a cave y using an open corridor, all corridors connected to the cave x change their state: all open corridors become closed, all closed corridors become open. Indiana wants to go from cave 1 to cave n going through as small number of corridors as possible. Help him find the optimal path, or determine that it is impossible to get out of catacombs.
输入格式
The first line contains two integers n and m ( 2≤n≤3⋅105 , 0≤m≤3⋅105 ) — the number of caves and the number of open corridors at the initial moment.
The next m lines describe the open corridors. The i -th of these lines contains two integers ui and vi ( 1≤ui,vi≤n , ui=vi ) — the caves connected by the i -th open corridor. It is guaranteed that each unordered pair of caves is presented at most once.
输出格式
If there is a path to exit, in the first line print a single integer k — the minimum number of corridors Indians should pass through ( 1≤k≤106 ). In the second line print k+1 integers x0,…,xk — the number of caves in the order Indiana should visit them. The sequence x0,…,xk should satisfy the following:
- x0=1 , xk=n ;
- for each i from 1 to k the corridor from xi−1 to xi should be open at the moment Indiana walks along this corridor.
If there is no path, print a single integer −1 .
We can show that if there is a path, there is a path consisting of no more than 106 corridors.
输入输出样例
输入#1
4 4 1 2 2 3 1 3 3 4
输出#1
2 1 3 4
输入#2
4 2 1 2 2 3
输出#2
4 1 2 3 1 4