易炸物LA3644(并查集)
[cpp]#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 100000 + 10;int f[maxn];int find(int x) {return f[x] != x ? f[x] = find(f[x]) : x;}int main() {int x, y;while(scanf("%d", &x) == 1) {for(int i = 0; i <= maxn; i++) {f[i] = i;}int refuse_num = 0;while(x != -1) {scanf("%d", &y);x = find(x); y = find(y);if(x == y) {++ refuse_num;}else{f[x] = y;}scanf("%d", &x);}printf("%d\n", refuse_num);}}
补充:软件开发 , C++ ,