POJ 2524 Ubiquitous Religions (带权并查集)
来源:互联网 发布:ppt文字环绕图片mac 编辑:程序博客网 时间:2024/05/21 07:01
题目链接:Ubiquitous Religions
带权并查集,记录集合个数即可
代码:
#include <stdio.h>#include <string.h>const int N = 50005;int n, m, parent[N];int find(int x) { if (x == parent[x])return x; return parent[x] = find(parent[x]);}int main() { int cas = 0; while (~scanf("%d%d", &n, &m) && n + m) {for (int i = 1; i <= n; i++) parent[i] = i;int a, b, ans = n;while (m--) { scanf("%d%d", &a, &b); int pa = find(a); int pb = find(b); if (pa != pb) {parent[pa] = pb;ans--; }}printf("Case %d: %d\n", ++cas, ans); } return 0;}
0 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 (并查集)
- 练习:逻辑运算与位运算实现除法运算,加法运算
- 串口通信程序中十六进制格式发送和接收实现
- FFT的详细解释
- Ubuntu手动安装MySQL
- OOP初始化
- POJ 2524 Ubiquitous Religions (带权并查集)
- HDU 1039 Easier Done Than Said?
- 【旋转矩阵】Rotate Image
- linux win7双系统
- OC block的简单使用
- 黑马程序员_java基础知识(5)枚举的简单理解
- POJ 1733 Parity game(离散化+带权并查集)
- 整理JS的prototyp,call用法深入理解
- 在ubuntu系统上,beagleboneblack借用usb实现网络与主机共享