当前位置:网站首页>2022.2.16
2022.2.16
2022-06-26 04:39:00 【bu_ xiang_ tutou】
10:00----10:30 13:00-----16:00 17:00---19:00
Today, I pushed the suitcase
tuixiangzi (c++)_bu_xiang_tutou The blog of -CSDN Blog
19:00---20:30
【 Templates 】 Minimum spanning tree
prim Solve the algorithm once
#include<bits/stdc++.h>
using namespace std;
#define inf 1e4+10
int dis[5009],v[5009],r[5009][5009],an,cnt,n,m;
int main()
{
int i,x,y,z;
cin>>n>>m;
for(x=1;x<=n;x++)
{
for(y=1;y<=n;y++)
{
if(x==y)
r[x][y]=0;
else
r[x][y]=inf;
}
}
for(i=1;i<=m;i++)
{
cin>>x>>y>>z;
r[x][y]=min(z,r[x][y]);
r[y][x]=min(z,r[y][x]);// Undirected graph
}
for(i=1;i<=n;i++)
dis[i]=r[1][i];
dis[1]=0;
v[1]=1;
while(cnt<n-1)
{
int min=inf,ans=-1;
for(i=1;i<=n;i++)// Find the minimum distance value
{
if(min>dis[i]&&v[i]==0)
{
min=dis[i];
ans=i;
}
}
v[ans]=1;
cnt++;
an+=dis[ans];
for(i=1;i<=n;i++)// Update distance value
{
if(v[i]==0&&dis[i]>r[ans][i])
{
dis[i]=r[ans][i];
}
}
}
int sign=0;
for(i=1;i<=n;i++)
{
if(v[i]==0)
{
sign=1;
printf("orz");
break;
}
}
if(sign==0)
cout<<an;
return 0;
} This code can only ac79, Three answers are out of time
#include<bits/stdc++.h>
using namespace std;
#define inf 1e4+10
int dis[5009],v[5009],an,n,m;
struct node{
int next;
int end;
int v;
}lu[200009];
int head[200009],cnt;
void add(int x,int y,int z)
{
cnt++;
lu[cnt].end=y;
lu[cnt].v=z;
lu[cnt].next=head[x];
head[x]=cnt;
}
int main()
{
int i,x,y,z,t=0;
cin>>n>>m;
for(i=1;i<=m;i++)
{
cin>>x>>y>>z;
add(x,y,z);
add(y,x,z);// Undirected graph
}
for(i=1;i<=n;i++)
dis[i]=inf;
dis[1]=0;
v[1]=1;
int ans=1;
while(t<n-1)
{
int min=inf;
v[ans]=1;
for(i=head[ans];i!=0;i=lu[i].next)// Find the minimum distance value
{
int b=lu[i].end,c=lu[i].v;
if(dis[b]>c&&v[b]==0)
{
dis[b]=c;
}
}
for(i=1;i<=n;i++)// Update distance value
{
if(v[i]==0&&min>dis[i])
{
min=dis[i];
ans=i;
}
}
an+=dis[ans];
t++;
}
int sign=0;
for(i=1;i<=n;i++)
{
if(v[i]==0)
{
sign++;
}
}
if(sign==1)
cout<<an;
else
printf("orz");
return 0;
}
边栏推荐
- PHP small factory moves bricks for three years - interview series - my programming life
- Multipass中文文档-使用Packer打包Multipass镜像
- Rdkit chemical formula molecular formula search
- 记录一次循环引用的问题
- mysql高级学习(跟着尚硅谷老师周阳学习)
- PHP splits a string into arrays
- CTF PHP audit bypasses filtering learning from topics
- Mobile terminal pull-down loading pull-down loading data
- What is the best way to store chat messages in a database? [Close] - best way to store chat messages in a database? [closed]
- Install Damon database
猜你喜欢

Modify the number of Oracle connections

Nabicat连接:本地Mysql&&云服务Mysql以及报错

Microsoft prohibits Russian users from downloading and installing win10/11

Rdkit chemical formula molecular formula search

Multipass中文文档-设置驱动
![[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface](/img/37/84b7d59818e854dac71d6f06700cde.jpg)
[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface

企业的产品服务怎么进行口碑营销?口碑营销可以找人代做吗?
![[Qunhui] this suite requires you to start PgSQL adapter service](/img/fb/1aea7eb833afc1a24531b612a98400.jpg)
[Qunhui] this suite requires you to start PgSQL adapter service

TP5 distinct method paging problem

Install dbeaver and connect Clickhouse
随机推荐
numpy 通用函数
Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
TP5 distinct method paging problem
Thinkphp6 using kindeditor
Sixtool- source code of multi-functional and all in one generation hanging assistant
1.21 learning summary
Database design (3): database maintenance and optimization
MySQL index details
Nabicat连接:本地Mysql&&云服务Mysql以及报错
Review of number theory
Oracle data pump table
Anti withdrawal test record
PHP small factory moves bricks for three years - interview series - my programming life
Laravel file stream download file
Simple use of redis in laravel
pip 批量完全卸载包
NVM installation and use and NPM package installation failure record
Text horizontal alignment attribute text align and element vertical alignment attribute vertical align
Group by and order by are used together
Multipass中文文档-使用Packer打包Multipass镜像