1e5的数据量在某些情况可能导致
int find(int x){ if(x==fa[x]) return x; else fa[x]=find(fa[x]); }
并查集查找时栈溢出
修改成迭代版即可
inline int find(int x){ while (x != fa[x]) { fa[x] = fa[fa[x]]; // 路径压缩(迭代版) x = fa[x]; } return x; }
如有类似问题可以尝试食用
但其他人使用相同代码都不会有问题,所以不确定是不是我的代码其他部分问题关联到其栈溢出