正文
增加 10 行删除 10 行
1234517 行未改动23242526272829303132333435363738395 行未改动45464748495051525354558 行未改动参考资料:https://blog.csdn.net/yjr3426619/article/details/82315133https://www.cnblogs.com/yifusuyi/p/9404672.htmlP196 银河英雄传说17 行未改动while(ch >= '0' && ch <= '9') { s = (s << 3) + (s << 1) + (ch ^ 48); ch = getchar(); }return s * w;}int t, fa[N], siz[N], sum[N];//siz[i]:i所在的链的规模//sum[i]:i到其所在根节点的距离int find(int x) {if(x == fa[x]) return x;else {int t = fa[x]; //先记录下fafa[x] = find(fa[x]); // 当返回时,fa[x]已经改变,即当此句执行完后 fa[x] != tsiz[x] = siz[t];sum[x] += sum[t]; // 合并父亲的权值}return fa[x];}//带权并查集实际上就类似于前缀和,通过已知的两个相对信息求出一个绝对信息5 行未改动if(c == 'M') {int x = read(), y = read();int a = find(x), b = find(y);if(a == b) continue;fa[a] = b; //将以a为首的链 连到b为首的链sum[a] = siz[b]; //a到跟节点(b)的距离 = b的规模siz[b] += siz[a]; //b 所在的规模 加入了a的规模siz[a] = siz[b];}if(c == 'C') {int x = read(), y = read();8 行未改动1234517 行未改动23242526272829303132333435363738395 行未改动45464748495051525354558 行未改动参考资料:https://blog.csdn.net/yjr3426619/article/details/82315133https://www.cnblogs.com/yifusuyi/p/9404672.htmlP196 银河英雄传说17 行未改动while(ch >= '0' && ch <= '9') { s = (s << 3) + (s << 1) + (ch ^ 48); ch = getchar(); }return s * w;}int t, fa[N], siz[N], sum[N];//siz[i]:i所在的链的规模//sum[i]:i到其所在根节点的距离int find(int x) {if(x == fa[x]) return x;else {int t = fa[x]; //先记录下fafa[x] = find(fa[x]); // 当返回时,fa[x]已经改变,即当此句执行完后 fa[x] != tsiz[x] = siz[t];sum[x] += sum[t]; // 合并父亲的权值}return fa[x];}//带权并查集实际上就类似于前缀和,通过已知的两个相对信息求出一个绝对信息5 行未改动if(c == 'M') {int x = read(), y = read();int a = find(x), b = find(y);if(a == b) continue;fa[a] = b; //将以a为首的链 连到b为首的链sum[a] = siz[b]; //a到跟节点(b)的距离 = b的规模siz[b] += siz[a]; //b 所在的规模 加入了a的规模siz[a] = siz[b];}if(c == 'C') {int x = read(), y = read();8 行未改动