TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

The enemy has n cities connected by m roads. We have bombers that can destroy roads. The Bomb, Divide and Conquer strategy dictates that if we separate the enemy's cities from each other, then the two (or more) pieces will be easier to secure. Bombing a road has a cost (fuel, risk factor, etc.) What is the minimum total cost of bombing enough roads to ensure that there is some pair of cities that have no path between them? A path is a sequence of connected roads.

Input Format

The first line of input gives the number of cases, N. N test cases follow. Each one starts with two lines containing n (2≤n≤150) and m (0≤mn(n-1)/2). The next m lines contain m triples of integers denoting two different cities (between 1 and n) that are connected by a road and the cost of destroying that road (between 1 and 1000).

Output Format

For each test case, output one line containing "Case #x:" followed by the total cost of disconnecting a pair of cities.

Sample Input 1

4
5
4
1 2 100
2 3 299
3 5 400
5 4 99
3
3
1 2 10
2 3 20
1 3 40
4
5
1 2 10
2 3 100
3 4 10
4 1 100
1 3 10
3
1
1 2 1000

Sample Output 1

Case #1: 99
Case #2: 30
Case #3: 30
Case #4: 0

Hints

you can search information about Stoer-Wagner Algorithm.

Problem Source

Migrated from old NTUJ.

uva10989

Subtasks

No. Testdata Range Score

Testdata and Limits

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