月度归档: 2021年3月

3 篇文章

[并查集模板题]连通分块
输入格式 输入的第一行包含两个整数n, m n代表图中的点的个数,m代表边的个数 接下来m行,每行2个正整数,表示图中连通的两点。 输出格式 输出1行,与1连通的点的集合,并按升序排列输出。 样例输入 6 3 1 2 2 3 3 4 样例输出 1 2 3 4 代码 #include<iostream> #include<map> #include<set> using names…
并查集模板
int pre[N]; //递归方式 int find_1(int x) { if(pre[x]!=x) pre[x]=find(pre[x]); return pre[x]; } //非递归方式 int find_2(int x) { if(pre[x]!=x) while(pre[x]!=pre[pre[x]]) pre&…