rt,感觉这个问题比较有意思
实现代码如下:
int fx[ 1000006 ]; int find(int x){ return x == fx[ x ] ? x : fx[ x ] = find(fx[ x ]); } void merge(int x, int y){ x = find(x), y = find(y); if(rand() & 1) swap(x, y); fx[ x ] = y; }