并查集其实维护的就是一个树形结构 int Find(int x){ if(pre[x]==x) return x; pre[x]=Find(pre[x]); return pre[x]; } 带权 的还没学会,再努力吧