大家快来A水题(sdut_2805)
来源:互联网 发布:php防止ddos 编辑:程序博客网 时间:2024/05/22 12:11
#include <stdio.h>#include <stdlib.h>#include <string.h>int a[2010];int find(int x){ while(x != a[x]){ x = a[x]; } return x;}void merge(int x, int y){ int f1, f2; f1 = find(x); f2 = find(y); if(f1 != f2){ a[f1] = f2; }}int main(){ int n, m; while(~scanf("%d %d", &n, &m)){ int i; for(i = 1;i <= n;i++){ a[i] = i; } int u, v; for(i = 0;i < m;i++){ scanf("%d %d", &u, &v); merge(u,v); } int sum = 0; for(i = 1;i <= n;i++){ if(a[i] == i){ sum++; } } printf("%d\n", sum); } return 0;}
1 0
- 大家快来A水题(sdut_2805)
- 大家快来A水题
- 大家快来A水题
- 大家快来A水题
- 大家快来A水题
- 大家快来A水题
- 大家快来A水题
- SDUTOJ 2805 大家快来A水题
- SDUT 2829 大家快来A水题
- SDUT 2805 大家快来A水题
- sdutacm-大家快来A水题
- SDUT 2805 大家快来A水题
- 大家快来a水题 n 55!w ! pue n a^o7 ! n paau ! (sdut oj2413)
- 大家快来帮帮我
- 大家快来帮帮我 谢谢啦!
- 100本Java电子书 大家快来下载
- 大家快来帮帮我吧,快要崩溃了
- 金山快盘——大家来注册吧
- [STL] list的使用
- 详解HTML中的window对象和document对象
- Spring webflow:上传多个文件
- Android使用SharedPreferences保存HashSet<String>数据不能更新成功
- 第四章-结构体
- 大家快来A水题(sdut_2805)
- 大数阶乘算法
- ORACLE 锁机制
- HDU 4245
- java对象与json对象间的相互转换
- Android基于金融类应用程序的破解以及防护
- Activity AndroidManifest的启动模式
- 灯塔(LightHouse)
- 使用国内的镜像服务器更新android sdk