POJ2524 Ubiquitous Religions(并查集)
来源:互联网 发布:和父母关系不好知乎 编辑:程序博客网 时间:2024/05/22 03:21
题意:
学校中每个人都有宗教信仰,现在只能知道某些人的宗教信仰相同,求总共有几种宗教
要点:
水题,跟HDU1213一毛一样,都是求最后集合个数,早知道不做了
#include<stdio.h>#include<string.h>#include<stdlib.h>#define maxn 50050int p[maxn], rank[maxn];int m, n,num;void init(){for (int i = 1; i <= m; i++){p[i] = i;rank[i] = 0;}}int find(int x){if (p[x] == x) return x;return p[x] = find(p[x]);}void merge(int x, int y){x = find(x);y = find(y);if (x == y) return;if (rank[x] > rank[y]){p[y] = x;num--;}else{p[x] = y;if (rank[x] == rank[y]) rank[y]++;num--;}}int main(){int kase = 1, x, y;while (~scanf("%d%d", &m, &n), n + m){init();//初始化不能忘记num = m;while (n--){scanf("%d%d", &x, &y);merge(x, y);}printf("Case %d: %d\n", kase++,num);}return 0;}
0 0
- POJ2524 Ubiquitous Religions 并查集
- poj2524 Ubiquitous Religions 并查集入门
- POJ2524 Ubiquitous Religions 并查集
- 【并查集】:poj2524,Ubiquitous Religions
- 并查集-poj2524-Ubiquitous Religions
- POJ2524 Ubiquitous Religions(并查集)
- POJ2524 Ubiquitous Religions 并查集
- POJ2524 Ubiquitous Religions(简单并查集)
- POJ2524 Ubiquitous Religions (并查集)
- POJ2524--Ubiquitous Religions(并查集)
- POJ2524 Ubiquitous Religions (并查集)
- POJ2524 Ubiquitous Religions (并查集)
- POJ2524——Ubiquitous Religions(并查集)
- POJ2524 Ubiquitous Religions 暨并查集入门
- POJ2524 - Ubiquitous Religions (并查集的基础应用)
- poj2524——Ubiquitous Religions(并查集)
- POJ2524——Ubiquitous Religions 并查集基础
- POJ2524 Ubiquitous Religions —— 并查集
- 双链表的各种基本运算
- some question of Gradle
- Android-ImageView的属性
- Linux C实现简单的UDP服务器客户端通信
- Linux下LVS搭建负载均衡集群
- POJ2524 Ubiquitous Religions(并查集)
- QT 的 Graphics View 系统
- android获取手机IP及&0xFF详解
- 很简单的JAVA反射教程
- codeforces 651A Joysticks
- 【02单表查询】——02:TOP
- 使用fluentd管理docker日志
- Qt的Graphics-View框架和OpenGL结合详解
- 对象深复制之输出流转输入流