链接:
https://ac.nowcoder.com/acm/contest/33192/H
来源:牛客网
Grammy has a connected undirected graph
GGG with two special vertices
AAA and
BBB. Each of the vertices has a number
pip_ipi written on it, where
p1,p2,…,pnp_1,p_2,\dots,p_np1,p2,…,pn is a permutation of size
nnn.
Grammy thinks these numbers on vertices are too chaotic. She wants to reorder the numbers such that for each vertex
xxx, there exists a path satisfying the following conditions:
1. The path starts from
AAA and ends at
BBB.
2. The path contains vertex
xxx.
3. The numbers along the path are strictly increasing.
Sadly, in each operation, Grammy can only choose a
simple path starting from
AAA and ending at an arbitrary vertex, then shift the numbers on the simple path by 1. That is, if the vertices on the simple path chosen by Grammy contains
a1,a2,…,ak−1,aka_1, a_2, \dots,a_{k-1}, a_ka1,a2,…,ak−1,ak, then after Grammy's operation, these vertices will become
a2,a3,…,ak,a1a_2, a_3, \dots, a_k, a_1a2,a3,…,ak,a1.
Additionally, Grammy can only operate no more than
1000010\,00010000 times.
Grammy cannot find out any plan to solve this problem, so she asked you for help.
Please help Grammy to determine whether she can reorder the numbers. You also need to output a solution if it exists.