TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

You are given a weighted undirected graph with edge weight denoting the capacity of the edge. Now given a number x, output how many unordered (s,t) pairs are there in the graph such that minCut(s,t) <= x. A Cut is a partition of the vertices of a graph into two sets such that s and t belong to different set after the partition. In weighted graphs, the size of a cut is defined to be the sum of weights of the edges crossing the cut. minCut is a cut whose size is the least possible.

Input Format

There are multiple test case in the input file, terminated by EOF. For each test case the first line contains two integers n and m, denoting the number of vertices and the number of edges in the graph. Next m lines contain 3 integers u,v,c denoting an undirected of capacity c between vertices u and v; 1 <= u,v <= n. Next line contains q, the number of queries. Next q line contains one number each which denotes the input x for ith query.


Note: there can be multiple edges between a pair of vertices.


Constraints


  • Number of test cases <= 20

  • n<=150

  • m<=3,000

  • q<=30

  • Every weights are less than or equal to 1,000,000

Output Format

The output for each test case should consist of q lines with one integers in each of them denoting the number of unordered (s,t) pairs corresponding to that query. There is no need to print any blank lines between test cases.


Note: The timelimit for the problem is somewhat strict.

Sample Input 1

1
5 0
1
0

Sample Output 1

10

Hints

Problem Source

Migrated from old NTUJ.

CodeCraft'09

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200