模板—Kruskal
2024-10-20 08:45:39
int getf(int x){return (f[x]==x)?x:f[x]=getf(f[x]);}
void hb(int x,int y){x=getf(x),y=getf(y),f[y]=x;}
inline void add(int u,int v,int w,int c);
int kruskal()
{
int num=;ans=;
for(int i=;i<=v;i++)f[i]=i;
sort(ed+,ed+num_e+);
for(int i=;i<=num_e;i++)
if(getf(u(i))!=getf(v(i)))
{
ans+=w(i);
hb(u(i),v(i));
if(!c(i))num++;
}
return num;
}
最新文章
- DOM加载过程中ready和load的区别
- Sql Server系列:数据库对象
- jquery中的$的特殊用法
- Beaglebone Black从零开始系列教程大汇总!
- BZOJ 1853: [Scoi2010]幸运数字
- Code Snippet
- 【java】: 操作excel2007/2003
- Linux 求文件交集 差集等
- 13.python笔记之pyyaml模块
- mediawiki 的使用
- easyui源码翻译1.32--DateTimeBox(日期时间输入框)
- 使用SharePoint管理中心管理服务
- KVM 虚拟化基本搭建
- 列表操作之定义,切片(取元素)(Python)
- idea web项目动态部署
- SecureCRT永久设置保护眼睛配色方案
- talk命令帮助文档(ubuntu 18.04)
- Fiddler抓包使用教程-基本功能介绍
- ubuntu git生成ssh key (公钥私钥)配置github或者码云
- 我的第一个网络爬虫 C#版 福利 程序员专车