#P3329. [ZJOI2011] 最小割

[ZJOI2011] 最小割

Description

Xiaobai learned a new concept—minimum cut—in a graph theory class. After class, Xiaobai wrote the following in the notebook:

For a graph, a partition of the vertices divides all vertices into two parts. If vertices ss and tt are not in the same part, then this partition is called a cut with respect to s,ts,t. For a weighted graph, the sum of the weights of all edges whose endpoints lie in different parts is defined as the capacity of this cut, and the minimum cut of s,ts,t is the cut with the minimum capacity among all cuts with respect to s,ts,t.

Given an undirected graph, Xiaobai has several questions of the form “how many unordered pairs of vertices have minimum-cut capacity not exceeding xx”. Xiaolan would like to answer these questions but is currently busy mining wooden blocks, so as Xiaolan’s friend, the task falls on you.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case, the first line contains two integers n,mn,m, the number of vertices and edges.

The next mm lines each contain three integers u,v,cu,v,c, indicating an undirected edge (u,v)(u,v) with weight cc. Multiple edges are allowed.

Then a line with an integer qq follows, the number of queries. Each of the next qq lines contains an integer xx describing one query.

Output Format

For each test case, output qq lines, each containing one integer: the answer to the corresponding query. For a qualifying pair (p,q)(p,q) and the pair (q,p)(q,p), count only once.

Output one empty line between two consecutive test cases.

1
5 0
1
0
10

Hint

For 100%100\% of the testdata, 1T101 \leq T \leq 10, 1n1501 \leq n \leq 150, 0m30000 \leq m \leq 3000, 0x23110 \leq x \leq 2^{31}-1, 0q300 \leq q \leq 30, 1u,vn1 \leq u,v \leq n, 0c1060 \leq c \leq 10^6.

Translated by ChatGPT 5