CF1648F.Two Avenues

NOI/NOI+/CTSC

通过率:0%

时间限制:8.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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. 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.

为了使贝尔兰首都对游客更具吸引力,伟大的国王提出了如下计划:从城市中选择两条街道并将其命名为“大道”。当然,这些大道将被宣布为极其重要的历史场所,以吸引来自世界各地的游客。

贝尔兰首都可用一个图来表示,其中顶点代表十字路口,边代表连接两个十字路口的街道。该图共有 nn 个顶点和 mm 条边;任意街道均可双向通行;仅通过街道即可从任一十字路口到达另一任意十字路口;每条街道连接两个不同的十字路口;且不存在两条街道连接同一对十字路口。

为减少普通市民在大道上的通行流量,决定在每条大道的两个方向上均设置通行费。现在沿任一大道通行一次需支付 11 图格里克(tugrik);其余街道则无需付费。

分析人员收集了 kk 名市民的样本,其中第 ii 名市民需从十字路口 aia_i 前往十字路口 bib_i 上班。在选定两条大道后,每名市民均会选择总费用最小的路径前往工作地点。

为使收入最大化,决定将两条街道选为大道,使得这 kk 名市民所支付的图格里克总额最大。请帮助国王:根据给定的城市结构图及市民样本,确定应选哪两条街道作为大道,并计算在此选择下市民总共需支付多少图格里克。

输入格式

Each test consists of multiple test cases. The first line contains one integer tt (1≤t≤1051 \leq t \leq 10^5) — the number of test cases.

The first line of each test case contains two integers nn and mm (3≤n≤500 0003 \leq n \leq 500\,000, n−1≤m≤500 000n - 1 \leq m \leq 500\,000, m≤n(n−1)2m \le \frac{n (n - 1)}{2}) — the number of crossroads and streets, respectively.

The next mm lines contain the description of streets, ii-th line contains two integers sis_i and fif_i (1≤si,fi≤n1 \leq s_i, f_i \leq n, si≠fis_i \neq f_i) — indexes 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 (1≤k≤500 0001 \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 (1≤ai,bi≤n1 \leq a_i, b_i \leq n, ai≠bia_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,K≤500 000M, K \le 500\,000.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(3≤n≤500 0003 \leq n \leq 500\,000,n−1≤m≤500 000n - 1 \leq m \leq 500\,000,m≤n(n−1)2m \le \frac{n (n - 1)}{2}),分别表示路口数量和街道数量。

接下来的 mm 行描述街道,其中第 ii 行包含两个整数 sis_i 和 fif_i(1≤si,fi≤n1 \leq s_i, f_i \leq n,si≠fis_i \neq f_i),表示第 ii 条街道连接的两个路口编号。保证不存在两条街道连接相同的路口对,且任意两个路口之间均可仅通过街道相互到达。

接下来一行包含一个整数 kk(1≤k≤500 0001 \leq k \leq 500\,000),表示样本中市民的数量。

接下来的 kk 行描述市民,其中第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,ai≠bia_i \neq b_i),表示第 ii 位市民从路口 aia_i 前往路口 bib_i 上班。

令 MM 表示所有测试用例中 mm 的总和,KK 表示所有测试用例中 kk 的总和。保证 M,K≤500 000M, 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.

对于每个测试用例,请输出该问题的答案。

第一行输出市民将支付的图格里克总额。

第二行输出两个整数 x1x_1 和 y1y_1 —— 表示第一条大道所连接的两个路口编号。

第三行输出两个整数 x2x_2 和 y2y_2 —— 表示第二条大道所连接的两个路口编号。

每条大道所连接的路口编号顺序可任意;所输出的每条街道必须属于城市原有的 mm 条街道之一,且所选的两条街道必须互不相同。

输入输出样例

  • 输入#1

    3
    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

    输出#1

    5
    4 2
    5 4
    5
    1 5
    3 2
    3
    7 6
    2 3

输入解题思路,AI测评打分。不知道怎么写?

首页