Beaverland
시간 제한1초메모리 제한512 MB
연결된 무가중 그래프에서 도시 1로부터 방문 목록까지의 거리가 엄격히 증가하도록 최대 5*10^5개의 간선을 추가하고, 불가능하면 불가능하다고 판정한다.
문제
Busy Beaver wants to have a tour in Beaverland! Beaverland consists of cities and bidirectional roads between them. It is guaranteed that it is possible to travel between any pair of cities along the roads, and that all roads have length .
So far, Busy Beaver has planned out his tour, and wishes to visit the cities . He views his tour to be interesting if where for two cities 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 more roads between any pairs of cities. Each of the added roads is also bidirectional and has length .
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 , the number of test cases. The description of each test case follows.
The first line of each test case contains three integers () --- the total number of cities, roads, and the number of cities in Busy Beaver's tour, respectively.
The next line contains integers (, distinct) --- the cities that Busy Beaver plans to visit.
The -th of the next lines contains two integers and (, ) --- indicating that there is a road between cities and . It is guaranteed that there is at most edge between any two distinct cities.
The sum of , the sum of , and the sum of over all test cases all do not exceed .
출력
For each test case, if it is possible to make the tour interesting, the first line of output should contain an integer () --- the number of added roads. Each of the next lines of output should then contain two integers (, ) 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 instead.
Due to judging constraints, you may use at most 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 causes , 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 we have , making the tour interesting.
In the fourth test case, the tour is already interesting, and no roads need to be added.