POJ P2524 Ubiquitous Religions
来源:互联网 发布:java while循环 编辑:程序博客网 时间:2024/06/06 03:01
题目大意:
在一堆关系复杂的宗教信仰大学生中求出不同宗教的最大数目。
并差集:
1.一直把信仰同一种宗教的X和Y合并到一个集合。
2.for一遍累加不同集合个数(宗教个数)
时间复杂度:O(M)
var f:array [0..50001] of longint; i,n,m,x,y,ans,g:longint;function find(c:longint):longint;begin if f[c]=c then exit(c); f[c]:=find(f[c]); exit(f[c]);end;begin readln(n,m); while (n<>0) or (m<>0) do begin inc(g); fillchar(f,sizeof(f),0); ans:=0; for i:=1 to n do f[i]:=i; for i:=1 to m do begin readln(x,y); if find(x)<>find(y) then f[find(x)]:=find(y); end; for i:=1 to n do if f[i]=i then inc(ans); writeln('Case ',g,': ',ans); readln(n,m); end;end.
1 2
- POJ P2524 Ubiquitous Religions
- POJ P2524 Ubiquitous Religions
- POJ P2524 Ubiquitous Religions
- POJ P2524 Ubiquitous Religions
- POJ P2524 Ubiquitous Religions 基础并查集
- POJ 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- poj 2504 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
- 《机器学习》周志华 读书笔记二补充(原创)
- 系统运维类大概了解
- hdu2087 剪花布条【kmp】
- 面试题30:最小的k个数
- javaScript练习:js和flash
- POJ P2524 Ubiquitous Religions
- BottomSheetBehavior的坑
- gym 101194 china final Problem H. Great Cells(数学,想法题,好题)
- 畅通工程
- 关于股权,写给技术人的合伙攻略
- How tomcat works——10 安全性
- 图像分割 1.基于阈值的算法
- 初识Vue.js
- 微信小程序开发文档详细讲解