题目1526:朋友圈
来源:互联网 发布:乔任梁 王思聪 知乎 编辑:程序博客网 时间:2024/04/29 22:01
#include <iostream>#include <fstream>#include <cstring>using namespace std;const int N = 100010;int p[N];int find(int x);int main(){ int n, m; int u, v; #ifndef ONLINE_JUDGE ifstream cin("d:\\OJ\\uva_in.txt"); #endif // ONLINE_JUDGE while (cin >> n, n) { cin >> m; memset(p, -1, sizeof(int) * n); for (int i = 0; i < m; i++) { cin >> u >> v; u--, v--; int pu = find(u), pv = find(v); if (pu != pv) { p[pv] = pu; } } int ans = 0; for (int i = 0; i < n; i++) { if (p[i] < 0) ans++; } cout << ans << endl; } return 0;}int find(int x){ return p[x] < 0 ? x : (p[x] = find(p[x]));}
0 0
- 题目1526:朋友圈
- 题目1526:朋友圈
- 题目1526:朋友圈
- 九度 题目1526:朋友圈
- 【九度】题目1526:朋友圈
- 九度题目1526:朋友圈
- 九度oj 题目1526:朋友圈
- <九度 OJ>题目1526:朋友圈
- 九度OJ题目 1526 朋友圈 并查集
- 九度OJ 题目1526:朋友圈(并查集)
- 九度OJ 题目1526:朋友圈(小米2013年校园招聘笔试题)
- 九度 1526:朋友圈
- 朋友圈
- 朋友圈
- 朋友圈
- 朋友圈
- 朋友圈
- 朋友圈
- Remove Duplicates from Sorted Array II
- Java产生随机数的几种方式
- Samba服务器
- 12-22
- 小众
- 题目1526:朋友圈
- spring mvc rest 优雅风格
- 跳跃表
- ICE:slice语言常识整理
- Nhibernate__01__入门
- 深入浅出CChart 每日一课——快乐高四第五课 梦想的天空,锦上添花之客户区自绘篇
- 在ubuntu下用openocd烧写程序到stm32开发板
- 找不到方向了
- qt连接mysql数据库实例