题解中写的都是递归形式的并查集,
Windows−LemonWWindows−LemonWWindows−LemonW下就基本爆栈了
那非递归的怎么写?
int getfa(int x){ if(fa[x] == x) return x; int rt = getfa(fa[x]); ad[x] += ad[fa[x]]; return fa[x] = rt; }
ad:当前所在位置