poj-3723 Conscription 最大生成树
2014-07-31 20:02
411 查看
题目链接
#include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 20005; const int Mod = 1000000007; int n,m,R,ans; int p[maxn]; struct node { int x,y,w; }edge[maxn*3]; bool cmp( node a,node b ) { return a.w > b.w; } int find( int x ) { return p[x] == x?x:p[x] = find( p[x] ); } void merge( int i ) { int x = find( edge[i].x ); int y = find( edge[i].y ); if( x != y ) { p[x] = y; ans += edge[i].w; } } int main() { #ifndef ONLINE_JUDGE freopen("data.txt","r",stdin); #endif int cas; scanf("%d",&cas); while( cas -- ) { ans = 0; scanf("%d%d%d",&n,&m,&R); for( int i = 0; i <= n+m; i ++ ) p[i] = i; for( int i = 0; i < R; i ++ ) { scanf("%d%d%d",&edge[i].x,&edge[i].y,&edge[i].w); edge[i].y += n; } sort( edge,edge+R,cmp ); for( int i = 0; i < R; i ++ ) merge( i ); printf("%d\n",(n+m)*10000-ans); } return 0; }
相关文章推荐
- POJ 3723 - Conscription(最大生成树)
- POJ 3723 Conscription (最大生成树)
- POJ 3723 conscription 最大生成树
- POJ 3723 Conscription 【最大生成树||最大权森林】
- poj 3723 Conscription(最大生成树)
- POJ--3723---Conscription---最大生成树
- poj 3723 Conscription(最大生成树)
- poj 3723 Conscription 【最大生成树|最大权森林】
- poj 3723 Conscription(最大生成树)
- POJ 3723 Conscription(最大生成树)
- POJ 3723 Conscription 最大生成树 + 并查集
- POJ 3723 Conscription(kruskal求最大生成树)
- POJ 3723 Conscription(最大生成树)
- POJ 3723 Conscription (最大生成树,kruskal,并查集)
- POJ-3723-Conscription最大生成树
- Poj 3723 Conscription -- 最大生成树(森林)
- poj 3723 Conscription(最大生成树 kruscal)
- POJ 3723 Conscription【最大生成树】
- poj 3723 kruscal,反边取最大生成树。
- 最大权森林·POJ-3723·Conscription