标签:
/* 并查集模板 by:mfcheer */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector> #include <set> #include <map> using namespace std; #define N 100010 int n, m; int fa[N]; int findd(int x) { if (fa[x] == -1) return x; else return fa[x] = findd(fa[x]); } void un(int x, int y) { int fx = findd(x); int fy = findd(y); if (fx == fy) return; fa[fx] = fy; } int main() { memset(fa, -1, sizeof(fa)); while (cin >> n >> m) { un(n,m); } return 0; }
标签:
原文地址:http://blog.csdn.net/u014427196/article/details/43087169