Problem J. Rikka with K-Match
时间限制 7000 ms
内存限制 64 MB
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 $G$ with $n$ nodes $(i,j)(1 \leq i \leq n,1 \leq j \leq m)$. There is an edge between $(a,b)$ and $(c,d)$ if and only if $|a-c|+|b-d|=1$. Each edge has its weight.
Now Yuta wants to calculate the minimum weight $K$-matching of $G$.
It is too difficult for Rikka. Can you help her?
An edge set $S$ is a match of $G=\langle V,E \rangle$ if and only if each nodes in $V$ connects to at most one edge in $S$. A match $S$ is a $K$-match if and only if $|S|=K$. The weight of a match $S$ is the sum of the weights of the edges in $S$. And finally, the minimum weight $K$-matching of $G$ is defined as the $K$-match of $G$ with the minimum weight.
输入数据
输出数据
For each testcase, print a single line with a single number -- the answer.
It is guaranteed that there exists at least one $K$-match.
样例输入
复制
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
样例输出
$ Mathjax font initiator $