标签:
Time Limit: 2000MS | Memory Limit: 30000K | |
Total Submissions: 20776 | Accepted: 7278 | |
Case Time Limit: 1000MS |
6
M 1 6
C 1
M 2 4
M 2 6
C 3
C 4
1
0
2
银河英雄传说。。
CODE:
#include <iostream> #include <cstdio> #include <cstring> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 30000 + 100 using namespace std; int F[MAX_N], D[MAX_N], S[MAX_N]; void find(int x){ if(F[x] != x){ find(F[x]); D[x] += D[F[x]]; F[x] = F[F[x]]; } } void Union(int x,int y){ find(x); find(y); x = F[x]; y = F[y]; F[x] = y; D[x] = S[y]; S[y] += S[x]; } int main(){ REP(i, 1, MAX_N) F[i] = i, D[i] = 0, S[i] = 1; int T, a, b; char c; scanf("%d", &T); while(T --){ scanf("\n%c", &c); if(c == ‘M‘) scanf("%d%d", &a, &b), Union(a, b); else scanf("%d", &a), find(a), printf("%d\n", D[a]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4532389.html