int find(int x){ //维护思路:将每一个节点直接连接到目前的根节点上 if (f[x] == x) return x; //利用递归,将回溯路径上的节点直接连在根节点上 f[x] = find(f[x]); return f[x]; }
int find(int x){ while(x!=f[x]) x=f[x]; return x; }