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 |
内牛满面,有没有大牛帮忙看看啊,多谢#include <iostream> #include <algorithm> #include <stdlib.h> #include <stdio.h> int num; using namespace std; struct students { int depth; int brief; }student[50001]; int find(int x) { if(student[x].brief!=x) student[x].brief=find(student[x].brief); return student[x].brief; } void merge(int p,int q) { if(find(p)==find(q)) return; num--; student[q].brief=find(p); } int main() { int n,m,i,j,time=1; while(1) { num=0; scanf("%d%d",&n,&m); if(n==0 && m==0) break; num=n; for(i=1;i<=n;i++) { student[i].brief=i; } while(m--) { scanf("%d%d",&i,&j); merge(i,j); } printf("Case %d:%d\n",time,num); time++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator