#P7487. [2017年杭电多校]Rikka with K-Match
[2017年杭电多校]Rikka with K-Match
Rikka with K-Match
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
Yuta has a graph with nodes . There is an edge between and if and only if . Each edge has its weight.
Now Yuta wants to calculate the minimum weight -matching of .
It is too difficult for Rikka. Can you help her?
An edge set is a match of if and only if each nodes in connects to at most one edge in . A match is a -match if and only if . The weight of a match is the sum of the weights of the edges in . And finally, the minimum weight -matching of is defined as the -match of with the minimum weight.
Input
The first line contains a number , the number of the testcases. And there are no more than testcases with . For each testcase, the first line contains three numbers $n,m,K(1 \leq n \leq 4 \times 10^4,1 \leq m \leq 4),1 \leq K \leq \lfloor \frac{nm}{2} \rfloor$. Then lines follow, each line contains numbers -- the weight of the edge between and . If , then lines follow, each line contains numbers -- the weight of the edge between and .
Output
For each testcase, print a single line with a single number -- the answer. It is guaranteed that there exists at least one -match.
Sample Input
3
3 3 1
3 4 5
8 9 10
1 2
6 7
11 12
3 3 2
3 4 5
8 9 10
1 2
6 7
11 12
3 3 3
3 4 5
8 9 10
1 2
6 7
11 12
Sample Output
1
5
12
Source
2017 Multi-University Training Contest - Team 5