Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
WA的不行了。。大牛们过来看看啊。。内赠美女。。#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { int x; int y; int cost; }; struct node nd[50005]; int root[20005]; int cmp(const void *a,const void *b) { return (*(node *)b).cost - (*(node *)a).cost; } int find_root(int a) { if(root[a]!=a) root[a]=find_root(root[a]); return root[a]; } void hebing(int a,int b) { int ra = find_root(a); int rb = find_root(b); if(ra!=rb) root[rb]=ra; } void init() { int i; for(i=0;i<=20002;i++) root[i]=i; } int main() { int t, r, i; __int64 cost=0; int count; int n,m; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&r); for(i=0;i<r;i++) scanf("%d%d%d",&nd[i].x,&nd[i].y,&nd[i].cost); init(); qsort(nd,n,sizeof(nd[0]),cmp); cost = (n+m)*10000; count=0; for(i=0;i<r;i++) { if(find_root(nd[i].x)!=find_root(nd[i].y + 10000)) { cost=cost - nd[i].cost; hebing(nd[i].x,nd[i].y+10000); count++; } if(count==n+m-1) break; } printf("%I64d\n",cost); } return 0; } 怎么会错咯。。kurka 算法么。。好不容易知道这么做,但是还是wa了。。 给点测试数据也行啊。。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator