#P15877. [ICPC 2026 NAC] Cable Pruning
[ICPC 2026 NAC] Cable Pruning
Description
You are helping to remodel a data center to make room for more GPUs. Over the years, the data center has become cluttered with superfluous network cable, and you have been asked to clean up the mess and reclaim as much unused cable as possible.
:::align{center}

An illustration of Sample Input 1. Servers in the same coupled pair are the same color. Cables to remove are indicated with a dashed line. :::
The data center has servers and network cables that link one server to another. Each cable has a length in feet. Traffic flows through network cables in both directions and the data center is initially connected: for every pair of servers there exists a path of network cables from to (possibly passing through intermediate servers). You've audited the data center network traffic to discover that only of servers need to communicate with each other. (Note that some servers might not be part of any coupled pair, or might be part of two or more coupled pairs.)
You now need to remove as much total length of cable as possible from the data center while keeping all coupled pairs connected to each other: for each such pair of servers there must exist a path from to passing through original network cables that you've kept in place.
Find the minimum total length of cable that must be kept in place to satisfy this constraint.
Input Format
The first line of input contains two space-separated integers and , the number of servers in the data center and number of coupled pairs of servers that you've discovered.
The next lines describe the network cables originally in the data center. Each line contains three space-separated integers , , and , specifying that a cable connects server to server and has length feet. There is at most one network cable connecting a pair of servers and the graph of servers and cables is connected.
Each of the next lines contains two space-separated integers and (, ) and describe a coupled pair of servers. Each coupled pair must remain connected by a path after you are done removing cable. All coupled pairs are distinct; and are considered the same and won't both be listed as coupled pairs.
Output Format
Print a single integer: the minimum total length of network cable (in feet) that must remain in place in order for all coupled server pairs to stay connected to each other.
8 3
5 3 5
1 7 20
3 8 8
7 5 15
5 2 12
1 6 9
5 1 10
7 4 7
3 4
8 2
1 7
57
5 1
1 3 3
4 2 4
3 4 2
5 2 2
4 1 6
2 1
9
京公网安备 11011102002149号