int find(int x) {
if (x != fa[x])
fa[x] = find(fa[x]);
return fa[x];
}
void union (int x, int y) {
int a = fin(x), b = find(y);
if (a != b)
fa[b] = a;
}
优化:http://www.360doc.com/content/15/0904/22/9482_496925571.shtml