当前位置:网站首页>2022 Henan Mengxin League No. 5: University of Information Engineering B - Transportation Renovation
2022 Henan Mengxin League No. 5: University of Information Engineering B - Transportation Renovation
2022-08-10 06:33:00 【WA_Automata】
B - traffic transformation
最小生成树问题.Think of intersections as points,Roads are treated as edge maps,The bare minimum spanning tree problem.
#include<bits/stdc++.h>
using namespace std;
const int N = 310;
struct stu{
int u,v,c;
};
int f[N];
int find(int x)
{
return f[x]==x?x:f[x]=find(f[x]);
}
void merge(int x,int y)
{
x=find(x),y=find(y);
if(x==y) return;
f[x]=y;
}
signed main()
{
int n,m;cin>>n>>m;
vector<stu> a(m);
for(int i=0;i<m;i++)
{
int u,v,c;cin>>u>>v>>c;
a[i]={
u,v,c};
}
for(int i=0;i<n;i++) f[i]=i;
sort(a.begin(),a.end(),[&](stu A,stu B){
return A.c<B.c;
});
int sum=0,mx=0;
for(int i=0;i<m;i++)
{
if(find(a[i].u)!=find(a[i].v))
{
merge(a[i].u,a[i].v);
if(mx<a[i].c) mx=a[i].c;
sum++;
}
}
cout<<sum<<" "<<mx<<endl;
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Qt列表下方增加弹出加载数据提示效果
OpenGL学习笔记(LearnOpenGL)-第六部分 变换
强化学习_11_Datawhale模仿学习
2022河南萌新联赛第(五)场:信息工程大学 K - 矩阵生成
【备份】《Unity Shader入门精要》配图
Talking about 3 Common Shadow Rendering Techniques in Games (3): Shadow Mapping
Teach you to change the kernel source code--sysfs virtual file system 1
QEMU guest与host通过网络通信——bridge/hostfwd/guestfwd
H2数据库如何动态插入数据
请问一下。Oracle CDC 连接器支持 LogMiner 和 XStream API 两种方式捕
各位大佬,oracle11g,cdc2.2,flink1.13.6,单表增量同步。在没新增数据的情
Qt中输入框在Win10上“Win+/“快捷键的一个Bug
老手也常误用!详解 Go channel 内存泄漏问题
Talking about the realization idea of "frame" of "frame synchronization online game"
UnityShader入门精要-基础纹理
程序员的十楼层。看看自己在第几层。PS:我的目标是:30岁第四层
数据库学习之数据类型
UE 游戏模式
Unity瓦片地图取消部分刚体效果
unityFps射击