HDU 1232 并查集裸题
来源:互联网 发布:matlab c 混合编程 编辑:程序博客网 时间:2024/06/08 14:34
#include<iostream>#include<cstdio>using namespace std;int N,M;int father[1005];int find(int x){ if(x == father[x]) return x; else return father[x] = find(father[x]);}int main(){ while(scanf("%d",&N) != EOF){ if(N == 0) break; scanf("%d",&M); for(int i = 1;i <= N;++i) father[i] = i; int x,y; int ans = N-1; for(int i = 0;i < M;++i){ scanf("%d%d",&x,&y); if(find(x) == find(y)) continue; ans --; father[find(x)] = find(y); } printf("%d\n",ans); } return 0;}
0 0
- HDU 1232 并查集裸题
- HDU-1213 并查集裸题
- hdu 1232 并查集小试牛刀
- hdu 1232 .hdu 1856 并查集 。。。
- HDU-1232 并查集
- hdu 1232 并查集
- HDU-1232(并查集)
- hdu 1232(并查集)
- hdu 1232 并查集
- HDU 1232 并查集
- hdu 1232 并查集
- hdu 1232(并查集)
- HDU 1232 并查集
- hdu 1232 并查集
- 并查集 hdu 1232
- HDU 1232(并査集)
- hdu 1232 并查集
- hdu 1232 并查集
- Material Design: NavigationView FlaotingActionBar SnackBar的使用,navigationview
- linux软件安装笔记
- SCons的使用
- 超实用PHP函数总结整理
- easyui datagrid表格自适应大小
- HDU 1232 并查集裸题
- Spring mvc 页面跳转方式
- mongodb安装、配置以及命令创建服务
- Spring4MVC+Spring4+Hibernate4整合系列--(二)StepByStep3
- springMVC+velocity做权限控制 控制到按钮!
- Kibana 5.x 加强安全
- poj 2505 A multiplication game 博弈基础
- java中如何用Quartz框架来实现定时任务(一)
- Enterprise Architect基于SVN多人协作环境搭建