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 <iostream> using namespace std; int fa[50001]; int getfa(int x){ return fa[x]==x?x:fa[x]=getfa(fa[x]); } void Union(int x,int y){ fa[getfa(x)] = getfa(y); } int main() { // freopen("in.txt","r",stdin); int n,m,i,x,y; for(int k =1 ; ; k ++){ scanf("%d %d", &n, &m); if(n == 0 && m == 0) break; for(i =1 ; i <= n ; i ++) fa[i] = i; for(i =1 ; i <= m ; i ++){ scanf("%d %d", &x, &y); if(getfa(x) != getfa(y)) n--; Union(x,y); } printf("case %d: %d\n", k, n); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator