#P13542. [OOI 2022] Two avenues

[OOI 2022] Two avenues

题目描述

In order to make the capital of Berland a more attractive place for tourists, the great king came up with the following plan: choose two streets of the city and call them avenues. Certainly, these avenues will be proclaimed extremely important historical places, which should attract tourists from all over the world.

The capital of Berland can be represented as a graph, the vertices of which are crossroads, and the edges are streets connecting two crossroads directly. In total, there are nn vertices and mm edges in the graph, you can move in both directions along any street, you can get from any crossroad to any other by moving only along the streets, each street connects two different crossroads, and no two streets connect the same pair of crossroads.

In order to reduce the flow of ordinary citizens moving along the great avenues, it was decided to introduce a toll on each avenue in both directions. Now you need to pay 11 tugrik for one passage along the avenue. You don't have to pay for the rest of the streets.

Analysts have collected a sample of kk citizens, ii-th of them needs to go to work from the crossroad aia_i to the crossroad bib_i. After two avenues are chosen, each citizen will go to work along the path with minimal cost.

In order to earn as much money as possible, it was decided to choose two streets as two avenues, so that the total number of tugriks paid by these kk citizens is maximized. Help the king: according to the given scheme of the city and a sample of citizens, find out which two streets should be made avenues, and how many tugriks the citizens will pay according to this choice.

输入格式

Each test consists of multiple test cases. The first line contains two integers, the first number is tt (1t1051 \leq t \leq 10^5) --- the amount of test cases. The second number is gg (0g70 \leq g \leq 7) --- the number of the group which this test belongs to. Description of the test cases follows.

The first line of each test case contains two integers nn and mm (3n5000003 \leq n \leq 500\,000, n1m500000n - 1 \leq m \leq 500\,000, mn(n1)2m \le \frac{n (n - 1)}{2}) --- the amount of crossroads and streets.

The next mm lines contain the description of streets, ii-th line contains two integers sis_i and fif_i (1si,fin1 \leq s_i, f_i \leq n, sifis_i \neq f_i) --- numbers of crossroads which are connected by ii-th street. It is guaranteed that no two streets connect the same pair of crossroads, you can get from any crossroad to any other by moving only along the streets.

The next line contains a single integer kk (1k5000001 \leq k \leq 500\,000) --- the amount of citizens in the sample.

The next kk lines contain the description of citizens, ii-th line contains two integers aia_i and bib_i (1ai,bin1 \leq a_i, b_i \leq n, aibia_i \neq b_i) --- ii-th citizen goes to work from crossroad aia_i to crossroad bib_i.

Let MM be the sum of mm over all test cases and KK be the sum of kk over all test cases. It is guaranteed that M,K500000M, K \le 500\,000.

输出格式

For each test case print the answer to the problem.

In the first line print the total amount of tugriks that will be paid by citizens.

In the second line print two integers x1x_1 and y1y_1 --- the numbers of crossroads that will be connected by the first avenue.

In the third line print two integers x2x_2 and y2y_2 --- the numbers of crossroads that will be connected by the second avenue.

The numbers of crossroads connected by an avenue can be printed in any order, each of the printed streets should be among mm streets of the city, chosen streets should be different.

3 0
6 5
1 2
2 3
2 4
4 5
4 6
3
1 6
5 3
2 5
5 5
1 2
2 3
3 4
4 5
5 1
6
1 5
1 3
1 3
2 4
2 5
5 3
8 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
7 1
1 8
3 6
4
2 5
3 7
2 5
7 8
5
4 2
5 4
5
1 5
3 2
3
7 6
2 3

提示

Scoring

Tests for this problem are divided into 7 groups. For each of the groups you earn points only if your solution passes all tests in this group and all tests in required groups. Note that passing sample tests is not required for some groups. Offline evaluation\textbf{Offline evaluation} means that your submission will be evaluated on the tests of the group only after the end of the contest.

Group Points Additional constraints < Required groups Comment
nn mm kk
0 00 -- Sample tests
1 1414 n20n \leq 20 m20m \leq 20 K1000K \leq 1000 00 t100t \leq 100
2 1111 n100n \leq 100 M2000M \leq 2000 K2000K \leq 2000 00--11
3 1515 n2000n \leq 2000 M20000M \leq 20\,000 K20000K \leq 20\,000 00--22
4 1616 -- M100000M \leq 100\,000 K100000K \leq 100\,000 00--33
5 1111 -- -- n=m+1n = m + 1
6 1919 Exactly 22 streets come out of each crossroad
7 1414 00--66 Offline-evaluation