The first line of input is the number of test case.
The first line of each test case contains three integers, N, M and R.
Then R lines followed, each contains three integers xi, yi and di.
There is a blank line before each test case.
1 ≤ N, M ≤ 10000
0 ≤ R ≤ 50,000
0 ≤ xi < N
0 ≤ yi < M
0 < di < 10000
For each test case output the answer in a single line.
2 5 5 8 4 3 6831 1 3 4583 0 0 6592 0 1 3063 3 3 4975 1 3 2049 4 2 2104 2 2 781 5 5 10 2 4 9820 3 2 6236 3 1 8864 2 4 8326 2 0 5156 2 0 1463 4 1 2439 0 4 4373 3 4 8889 2 4 3133
71071 54223
思路:最小生成树的模板题,只是在加边的时候让男生的点成为第i+n个点,其他的就没什么要注意的了。
比赛的时候先认为是模拟题,后来写在一半内心有一丝感觉飘过觉得应该是最小生成树,但还是坚持把模拟代码写完了,然后wa了,但那个时候比赛还有五分钟就结束了,,,,怎么说,这次比赛打得很烂,有一道很简单的英文题没写出来,很难受,交了四遍都wa了,当时大部分人都把那题过了,很是崩溃,有点不想做了。哎,这么简单的比赛做的这么惨,还是实力不够啊,真菜!!!!!!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#define inf 0x3fffffff
using namespace std;
typedef long long LL;
const int N=1e4+1;
int m,n,r,far[N*2];
struct node
{
int u,v,dis;
}e[N*5];
bool cmp(node x,node y)
{
return x.dis>y.dis;
}
int finf(int x)
{
return x==far[x]?x:far[x]=finf(far[x]);
}
int kruskal()
{
int ans=0;
for(int i=0;i<m+n;i++)
far[i]=i;
sort(e,e+r,cmp);
for(int i=0;i<r;i++)
{
int fa=finf(e[i].u);
int fb=finf(e[i].v);
if(fa!=fb)
{
far[fa]=fb;
ans+=e[i].dis;
}
}
return ans;
}
int main()
{
int t,x,y,d;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&r);
for(int i=0;i<r;i++)
{
scanf("%d%d%d",&x,&y,&d);
e[i].u=x;
e[i].v=y+n;
e[i].dis=d;
}
printf("%d\n",10000*(m+n)-kruskal());
}
}