Cutting edges one at a time
Time limit2sMemory limit512 MB
Delete edges of a weighted undirected graph one by one so that the total weight removed before s and t get disconnected is as large as possible.
- Level
Hard8 of 10
- Topics
- Graph, Minimum spanning tree, Greedy, Sorting
- Solved
- No attempts yet
Problem
You are given an undirected graph with vertices and edges. Every edge has a weight. You take edges from the edge list one at a time and delete them from the graph, in whatever order you like.
The moment two vertices and become disconnected, you stop deleting. Disconnected means there is no way to walk from one of them to the other along the remaining edges.
Choose the deletion order so that the total weight of the edges deleted up to the moment you stop is as large as possible. Print that maximum.
Input
The first line has the number of vertices and the number of edges . (, )
Each of the next lines has three integers , , , meaning the graph has an edge of weight between vertex and vertex . (, , )
The last line has two vertices and . (, )
The edge list may hold more than one edge between the same pair of vertices. At the start and are always connected.
Output
Print on one line the maximum total weight of the edges deleted up to the moment and become disconnected.