Train Driver
题号:NC52020
时间限制:C/C++/Rust/Pascal 8秒,其他语言16秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

It's time for training! WJJ, DYX and ZZH from the team Nonsense Time want to find a place in BUAA (shorten for Beihang University) to hold their team training. BUAA can be regarded as an undirected connected graph G = (V, E) with n nodes as places and m edges as routes, where the length of each edge is 1.

Since there is no fixed place in BUAA for programming competition training, they have to find a meeting place and make training at that place. They always want to minimize the total distance they need to consume from their previous locations to the meeting place so that they save more energy for training.

However, their previous locations are not always fixed as well. As we know, each of DYX and ZZH is always at one of the places they usually stay at, such as dormitory, canteen, etc., but WJJ may be at anywhere inside BUAA! They constantly need to estimate the total distance they would consume, so they build a statistic model for themselves.

In this model, DYX may show up with equal probability at a node randomly chosen from the set A, ZZH may show up with equal probability at a node randomly chosen from the set B, and WJJ may show up with equal probability at a node randomly chosen from BUAA. When they want training, they will find a place to meet such that the total distance can be minimized.

As the coach of Nonsense Time, please help them to calculate the expected minimum total distance based on this model.

输入描述:

There are multiple test cases. The first line contains an integer T (), indicating the number of test cases. Test cases are given in the following.

For each test case, the first line contains two integers n, m (), representing the number of nodes and the number of edges in BUAA respectively.

Each of the next m lines contains two integers u, v (), representing an undirected edge between the u-th node and the v-th one.

The next line begins with an integer S_A (), indicating the size of the set A, and then S_A distinct integers follow, representing the indices of nodes in the set A.

The last line begins with an integer S_B (), indicating the size of the set B, and then S_B distinct integers follow, representing the indices of nodes in the set B.

We ensure that each given index is ranged from 1 to n.

输出描述:

For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1, and y denotes the irreducible fraction form of the answer to this test case. Note that the denominator should be omitted when it equals 1.
示例1

输入

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

输出

复制
Case #1: 7/4
Case #2: 10/9