POJ 2524 Ubiquitous Religions
来源:互联网 发布:今日头条数据报告 编辑:程序博客网 时间:2024/05/16 08:24
题意的大体意思就是说有很多的同学信仰是不同的,他们之间是有联系的,求他们一共有多少个信仰。。。就是一个简单的并查集、、求根节点的个数。。。。
直接上代码,比较水啊、、、
#include <stdio.h>int f[100000];int find(int x){ while(x != f[x]) x = f[x]; return x;}void rank(int x, int y){ int x1, y1; x1 = find(x); y1 = find(y); if(x1 != y1) f[x1] = y1;}int main(){ int n, m, i, t, count, x, y; t = 1; while(~scanf("%d %d",&n, &m) && (n || m)) { count = 0; for(i = 1; i <= n; i++) f[i] = i; for(i = 0; i < m; i++) { scanf("%d %d",&x, &y); rank(x, y); } for(i = 1; i <= n; i++) if(f[i] == i) count++; printf("Case %d: ",t++); printf("%d\n",count); } return 0;}
- POJ 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- POJ-2524 Ubiquitous Religions
- Poj 2524 Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- POJ 2524 - Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- POJ-2524-Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- jQuery验证控件jquery.validate.js使用说明+中文API
- Android应用开发学习笔记之帧布局
- 通过CertEnroll在CA上(1创建证书请求2得到证书3安装证书)
- C++二进制文件读写
- Lua _ _ index 用法
- POJ 2524 Ubiquitous Religions
- CoreAnimation编程指南(简介)
- hive cli
- HDU 4276 The Ghost Blows Light(树形DP)
- 空间向量的应用
- Linux平台Oracle多个实例启动
- Text Reverse
- 如何使Android应用程序获得root权限
- 3、spring mvc sitemesh velocity整合