HDU 1232 畅通工程
来源:互联网 发布:php老虎机源码 编辑:程序博客网 时间:2024/06/06 04:42
点击打开题目链接
#include <bits/stdc++.h>using namespace std;int pre[1010];int Find(int x);int join(int x, int y);int main(){ int n, m; while(cin >> n, n) { for(int i = 1; i <= n; i++) { pre[i] = i; } cin >> m; for(int i = 1; i <= m; i++) { int x, y; cin >> x >> y; join(x, y); } int num = 0; for(int i = 1; i <= n; i++) { if(pre[i] == i) { ++num; } } cout << num-1 << endl; } return 0;}int Find(int x){ int r = x; while(pre[r] != r) r = pre[r]; int i = x, j; while(i != r) { j = pre[i]; pre[i] = r; i = j; } return r;}int join(int x, int y){ int fx = Find(x), fy = Find(y); if(fx != fy) { pre[fx] = fy; }}
0 0
- 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 - 畅通工程
- hdu 1232 畅通工程
- hdu 1232畅通工程
- hdu 1232 畅通工程
- HDU 1232 畅通工程
- Linux的时间和时区设置
- git补丁
- 程序性能数据采集工具--PAPI
- [Ljava.lang.String; cannot be cast to java.lang.String
- BZOJ3939: [Usaco2015 Feb]Cow Hopscotch
- HDU 1232 畅通工程
- spark运行过程中报错Could not locate executable null\bin\winutils.exe in the Hadoop binaries.解决
- 理解javascript中的MVVM开发模式
- elk之nginx
- 安卓编程的各种坑
- SICP 习题 (2.1.4)拓展练习——初论
- 1066. Root of AVL Tree (25)-PAT甲级真题
- jquery源码模仿编写01
- React Native 环境搭建(windows)