标签:cep cin ++ acm ane scanf sed traints style
http://acm.hdu.edu.cn/showproblem.php?pid=4496
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 4802 Accepted Submission(s): 1690
1 #include<cstring> 2 #include<cstdio> 3 #include<map> 4 #include<iostream> 5 using namespace std; 6 struct Edge{int u,v,res;}e[100005]; 7 int f[10005]; 8 int getf(int v){return f[v]==v?v:f[v]=getf(f[v]);} 9 int main() 10 { 11 int N,M,i,j,k; 12 while(cin>>N>>M){ 13 for(i=0;i<N;++i) f[i]=i; 14 int u,v,ans=N; 15 for(i=1;i<=M;++i) 16 { 17 scanf("%d%d",&e[i].u,&e[i].v); 18 } 19 for(i=M;i>=1;--i) 20 { 21 e[i].res=ans; 22 int fu=getf(e[i].u),fv=getf(e[i].v); 23 if(fu!=fv){ 24 f[fu]=fv; 25 ans--; 26 } 27 28 } 29 for(i=1;i<=M;++i) printf("%d\n",e[i].res); 30 } 31 return 0; 32 }
标签:cep cin ++ acm ane scanf sed traints style
原文地址:http://www.cnblogs.com/zzqc/p/7612364.html