Beaverland

시간 제한1초메모리 제한512 MB

요약
연결된 무가중 그래프에서 도시 1로부터 방문 목록까지의 거리가 엄격히 증가하도록 최대 5*10^5개의 간선을 추가하고, 불가능하면 불가능하다고 판정한다.
난이도

어려움10점 중 9점

유형
그래프, BFS, 그리디, 동적 계획법
정답자
아직 제출이 없습니다

문제

Busy Beaver wants to have a tour in Beaverland! Beaverland consists of NN cities and MM bidirectional roads between them. It is guaranteed that it is possible to travel between any pair of cities along the MM roads, and that all roads have length 11.

So far, Busy Beaver has planned out his tour, and wishes to visit the cities x_1,x_2,…,x_Kx\_1, x\_2, \dots, x\_K. He views his tour to be interesting if dist(1,x_1)<dist(1,x_2)<⋯<dist(1,x_K)\mathrm{dist}(1,x\_1) < \mathrm{dist}(1,x\_2) < \dots < \mathrm{dist}(1,x\_K) where dist(x,y)\mathrm{dist}(x, y) for two cities x,yx, y is equal to the length of the shortest path connecting the two cities.

However, it might not be the case that Busy Beaver's tour is currently interesting! To fix this, he can add up to 5⋅1055 \cdot 10^5 more roads between any pairs of cities. Each of the added roads is also bidirectional and has length 11.

Determine whether it is possible to make Busy Beaver's tour interesting by adding some roads (possibly none). Additionally, if it is possible, provide any valid construction.

입력

Each test contains multiple test cases. The first line of input contains a single integer TT (1≤T≤104)(1 \leq T \leq 10^4), the number of test cases. The description of each test case follows.

The first line of each test case contains three integers N,M,KN,M,K (1≤K≤N,N−1≤M≤2⋅1051 \le K \le N, N-1 \le M \le 2 \cdot 10^5) --- the total number of cities, roads, and the number of cities in Busy Beaver's tour, respectively.

The next line contains KK integers x_1,x_2,…,x_Kx\_1,x\_2, \dots, x\_K (1≤x_i≤N1 \le x\_i \le N, x_ix\_i distinct) --- the cities that Busy Beaver plans to visit.

The ii-th of the next MM lines contains two integers u_iu\_i and v_iv\_i (1≤u_i,v_i≤N1 \le u\_i, v\_i \le N, u_i≠v_iu\_i \neq v\_i) --- indicating that there is a road between cities u_iu\_i and v_iv\_i. It is guaranteed that there is at most 11 edge between any two distinct cities.

The sum of NN, the sum of MM, and the sum of KK over all test cases all do not exceed 2⋅1052 \cdot 10^5.

출력

For each test case, if it is possible to make the tour interesting, the first line of output should contain an integer LL (0≤L≤5⋅1050 \leq L \leq 5 \cdot 10^5) --- the number of added roads. Each of the next LL lines of output should then contain two integers u_i,v_iu\_i,v\_i (1≤u_i,v_i≤N1 \leq u\_i , v\_i \leq N, u_i≠v_iu\_i \neq v\_i) representing a road to be added.

If there are multiple solutions, print any of them. Otherwise, if there is no solution, print a single integer −1-1 instead.

Due to judging constraints, you may use at most 5⋅1055 \cdot 10^5 roads in total, over all test cases. It can be shown that this is enough to solve the problem.

힌트

In the first test case, adding a road between cities 1,21, 2 causes dist(1,1)=0,dist(1,2)=1dist(1,1) = 0, dist(1,2) = 1, making the tour interesting.

In the second test case, it can be shown that the task is impossible.

In the third test case, by adding a road between cities 1,31, 3 we have dist(1,3)=1,dist(1,5)=2dist(1,3) = 1, dist(1,5) = 2, making the tour interesting.

In the fourth test case, the tour is already interesting, and no roads need to be added.

예제1

  1. 예제 1

    입력
    4
    3 3 2
    1 2
    1 2
    1 3
    2 3
    3 3 3
    1 2 3
    1 2
    1 3
    2 3
    5 5 2
    3 5
    1 2
    2 3
    1 4
    4 5
    2 4
    6 6 5
    1 2 3 4 5
    1 2
    2 3
    3 4
    4 5
    5 6
    4 6
    
    예상 출력
    1
    1 2
    -1
    1
    1 3
    0