当前位置:网站首页>prim生成树
prim生成树
2022-08-01 22:42:00 【秦小咩】
# include<iostream>
# include<deque>
# include<vector>
# include<map>
# include<queue>
# include<cstring>
using namespace std;
typedef long long int ll;
ll inf=(1ll<<50);
int n,m;
ll ans;
ll nowdis[5050];
typedef struct
{
int b,e;
ll w;
} xinxi;
xinxi s[200000*3+10];
int len;
int f[200000*3+10];
int nex[200000*3+10];
void add(int x,int y,int z)
{
s[len].b=x;
s[len].e=y;
s[len].w=z;
nex[len]=f[x];
f[x]=len;
len++;
}
void prim()
{
int x=f[1];
for(int i=2;i<=n;i++)
{
nowdis[i]=inf;
}
while(x!=-1)
{
int j=s[x].e;
nowdis[j]=min(nowdis[j],s[x].w);
x=nex[x];
}
for(int i=2; i<=n; i++)
{
ll minn=inf;
int id=0;
for(int j=2; j<=n; j++)
{
if(nowdis[j]<minn&&nowdis[j])
{
minn=nowdis[j];
id=j;
}
}
ans+=minn;
nowdis[id]=0;
int x=f[id];
while(x!=-1)
{
int j=s[x].e;
if(s[x].w<nowdis[j])
{
nowdis[j]=s[x].w;
}
x=nex[x];
}
}
}
int main ()
{
memset(f,-1,sizeof(f));
cin>>n>>m;
for(int i=1; i<=m; i++)
{
int x,y;
ll z;
cin>>x>>y>>z;
add(x,y,z);
add(y,x,z);
}
prim();
for(int i=1;i<=n;i++)
{
if(nowdis[i])
{
cout<<"orz";
return 0;
}
}
cout<<ans;
return 0;
}
边栏推荐
- 10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享
- 选择合适的 DevOps 工具,从理解 DevOps 开始
- 系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
- Implementation principle of VGUgarbage collector (garbage collector)
- PHP算法之最接近的三数之和
- 解决 win10 下 ISE14.7的 iMPACT 崩溃问题 - FPGA 笔记
- 自建 Prometheus 采集腾讯云容器服务监控数据最佳实践
- 移动端人脸风格化技术的应用
- 复现gallerycms字符长度限制短域名绕过
- blender3.2.1 unit setting
猜你喜欢

No more rolls!After joining ByteDance for a week, he ran decisively.

2022年最新河北建筑八大员(机械员)模拟考试题库及答案

系统可用性:SRE口中的3个9,4个9...到底是个什么东西?

Go 微服务开发框架DMicro的设计思路

03、GO语言变量定义、函数

y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)

xctf攻防世界 Web高手进阶区 web2
![[深入研究4G/5G/6G专题-48]: 5G Link Adaption链路自适应-4-下行链路自适应DLLA-PDCCH信道](/img/6b/d4ff120493e878fcf5c9aa728eced7.png)
[深入研究4G/5G/6G专题-48]: 5G Link Adaption链路自适应-4-下行链路自适应DLLA-PDCCH信道

【数据分析03】

小程序毕设作品之微信美食菜谱小程序毕业设计成品(5)任务书
随机推荐
2022 edition of MySQL tutorial, top collection good, take your time
数据分析04
Yizhou Financial Analysis | The intelligent transformation of bank ATM machines is accelerated; the new Internet loan regulations bring challenges
(Translation) How the contrasting color of the button guides the user's actions
字符串——Trie
将vim与系统剪贴板的交互使用
JS prototype hasOwnProperty in 加方法 原型终点 继承 重写父类方法
移动端人脸风格化技术的应用
小程序毕设作品之微信体育馆预约小程序毕业设计成品(3)后台功能
解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”
number of solutions to solve a multivariate multi-degree equation
小程序毕设作品之微信美食菜谱小程序毕业设计成品(6)开题答辩PPT
xctf攻防世界 Web高手进阶区 webshell
2022年最新河北建筑八大员(机械员)模拟考试题库及答案
联邦学习在金融领域的发展和应用
Ten years after graduation, financial freedom: those things that are more important than hard work, no one will ever teach you
[Mobile Web] Mobile terminal adaptation
JS 数组去重(含简单数组去重、对象数组去重)
用virtualenv和Virtualenvwrapper虚拟环境管理工具创建虚拟环境
SQL Server(设计数据库--存储过程--触发器)