63pts求条
查看原帖
63pts求条
1408853
Augustus_Deception楼主2025/6/22 16:10

虽然但是#8,9,10 RE,#13 WA是什么鬼

#include<bits/stdc++.h>
using namespace std;
const int N=5e3;
struct edge
{
	int u,v,w;
}e[(N<<5)|7];
int n,m,ans,sum,cnt;
int fa[N|7];
bool cmp(edge a,edge b)
{
	return a.w<b.w;
}
int find(int x)
{
	if(x!=fa[x]) return fa[x]=find(fa[x]);
	return x;
}
void kru()
{
	sort(e+1,e+m+1,cmp);
	for(int i=1;i<=m;i++)
	{
		int u=find(e[i].u);
		int v=find(e[i].v);
		if(v==u) continue;
		ans+=e[i].w;
		fa[v]=u;
		cnt++;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++) cin>>e[i].u>>e[i].v>>e[i].w;	
	kru();
	cout<<ans<<'\n';
	return 0;
}/*
4 5
1 2 2
1 3 2
1 4 3
2 3 4
3 4 3
没判断ORZ
*/
2025/6/22 16:10
加载中...