标签:des style blog http color java os io
5 10 0 1 1 2 1 3 1 4 0 2 2 3 0 4 0 3 3 4 2 4
1 1 1 2 2 2 2 3 4 5
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define INF 0x3f3f3f3f 15 using namespace std; 16 const int maxn = 10010; 17 int uf[maxn],n,m; 18 int ans[maxn*10]; 19 int a[maxn*10],b[maxn*10]; 20 int Find(int x){ 21 if(x != uf[x]) 22 uf[x] = Find(uf[x]); 23 return uf[x]; 24 } 25 int main(){ 26 int i,j,k; 27 while(~scanf("%d %d",&n,&m)){ 28 for(i = 0; i <= n; i++) 29 uf[i] = i; 30 for(i = 1; i <= m; i++){ 31 scanf("%d %d",a+i,b+i); 32 } 33 ans[m] = n; 34 for(i = m; i; i--){ 35 int tx= Find(a[i]); 36 int ty = Find(b[i]); 37 uf[tx] = ty; 38 if(tx != ty){ 39 ans[i-1] = ans[i]-1; 40 }else ans[i-1] = ans[i]; 41 } 42 for(i = 1; i <= m; i++){ 43 printf("%d\n",ans[i]); 44 } 45 } 46 return 0; 47 }
BNUOJ 33895 D-City,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/crackpotisback/p/3925418.html