Grammy Sorting
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

Grammy has a connected undirected graph G with two special vertices A and B. Each of the vertices has a number p_i written on it, where  is a permutation of size n

Grammy thinks these numbers on vertices are too chaotic. She wants to reorder the numbers such that for each vertex x, there exists a path satisfying the following conditions: 

1. The path starts from A and ends at B

2. The path contains vertex x

3. The numbers along the path are strictly increasing. 

Sadly, in each operation, Grammy can only choose a simple path starting from A 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 , then after Grammy's operation, these vertices will become

Additionally, Grammy can only operate no more than  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. 

输入描述:

The first line contains 4 integers n,m,A,B (). 

The second line contains n integers  (). It is guaranteed that  is a permutation. 

In each of the next m lines, there are two integers u_i, v_i (), denoting that there is a bidirectional edge between u_i and v_i. It is guaranteed that the graph is connected. 

输出描述:

If Grammy cannot properly reorder the numbers, output -1 (without quotes). 

Otherwise output an integer op () in the first line, indicating the number of operations Grammy needs. 

For the following op lines, output an integer k, denoting the number of vertices on the chosen simple path. Then output k integers (), indicating the vertices on the simple path. These x_i should be distinct. 

It can be proved that if graph G can be properly reordered, there exists a solution with no more than operations. 

Note that you don't have to minimize op. If there are multiple solutions, output any of them. 
示例1

输入

复制
5 6 1 2
1 2 3 4 5
1 3
2 3
1 4
2 4
1 5
3 5

输出

复制
7
4 1 3 2 4
3 1 3 2
3 1 3 5
4 1 3 2 4
3 1 3 2
2 1 3
1 1
示例2

输入

复制
4 3 1 2
1 4 2 3
1 4
2 4
3 4

输出

复制
-1