K-matching
Time limit9sMemory limit512 MB
Given an n by m grid graph with edge weights, find the minimum total weight of K edges that share no endpoints (a K-matching).
- Level
Hard8 of 10
- Topics
- Dynamic programming, Binary search, Graph
- Solved
- No attempts yet
Problem
Consider a graph with nodes (, ). There is an edge between two nodes and if and only if . Each edge has a weight.
Find the minimum weight of a -matching in .
An edge set is a matching of if and only if each node in is connected to at most one edge in . A matching is a -matching if and only if . The weight of a matching is the sum of the weights of the edges in . The minimum weight -matching of is the -matching with the smallest possible weight.
Input
The first line contains an integer , the number of test cases (). At most test cases have .
For each test case, the first line contains three integers , and (, , ).
Then lines follow, each containing integers : the weights of the edges between and ().
If , then more lines follow, each containing integers : the weight of the edge between and ().
Output
For each test case, print a single line containing the minimum weight.