博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2524
阅读量:7212 次
发布时间:2019-06-29

本文共 674 字,大约阅读时间需要 2 分钟。

并查集水题

#include 
using namespace std;const int maxn=50010;int tot,m,n;struct node{ int rank; int data; int parent;}t[maxn];void init(){ for(int i=1;i<=n;i++) { t[i].data=i; t[i].rank=1; t[i].parent=i; }}int find(int p){ if(p!=t[p].parent) t[p].parent=find(t[p].parent);//路径压缩 return t[p].parent;//易错点}void Union(int x,int y){ int xp=find(x); int yp=find(y); if(xp!=yp) { if(t[xp].rank
>n>>m&&!(n==0&&m==0)) { init(); amount++; tot=n; for(int i=0;i
>x>>y; Union(x,y); } cout<<"Case "<
<<": "<
<

 

 

 

转载于:https://www.cnblogs.com/lj-vs-lishimin/archive/2012/10/15/2774376.html

你可能感兴趣的文章
我的友情链接
查看>>
案例分析--AD客户端登录验证缓慢问题
查看>>
rip v1不支持vlsm的原因
查看>>
【Rayeager PX2】Rayeager PX2开发板上安装FreeBSD
查看>>
拒绝枯燥,有意思的 Loading 页面动效设计
查看>>
我的友情链接
查看>>
在服务器托管中asp***的防范注意些什么?
查看>>
JS中sort排序
查看>>
js 对时间的操作
查看>>
我的LINUX之路----linux目录文件管理
查看>>
动态规划-最长上升子序列(LIS)
查看>>
python基础3——运算符
查看>>
如何修复崩溃的WordPress数据库表
查看>>
企业级市场,正成为IT老兵创业的最佳选择
查看>>
Eclipse下Maven工程多模块继承和聚合的创建
查看>>
Initialization of bean failed; nested exception is org.springframework.beans.factory.: 错误分析
查看>>
排序(二)
查看>>
OmniPlan 项目管理入门
查看>>
我的友情链接
查看>>
在 TMG 更新中心中使用 WSUS进行每日的定义更新
查看>>