为什么莫名其妙编译失败?
查看原帖
为什么莫名其妙编译失败?
1616821
__owen__楼主2024/12/30 00:40

就离谱

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
const int N = 100;
int cnt,n,m,ans,index;
using namespace std;
vector<vector<int>> broad(N,vector<int>(N));
vector<int> pre(N);
struct way {
	int x,y,w;
} e[999999];
int cmp(way a,way b) {
	return a.w < b.w;
}
int find(int x) {
	if(pre[x]==x)return x;
	return pre[x]=find(pre[x]);
}
signed main() {
	IOS;
	cin>>n;
	for(int i=1; i<=n; i++)pre[i]=i;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			cin>>broad[i][j];
		}
	}
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			e[index].x=i;
			e[index].y=j;
			e[index].w=broad[i][j];
			index++;
		}
	}
	sort(e,e+index,cmp);
	for(int i=0;i<index;i++){
		int x=find(e[i].x);
		int y=find(e[i].y);
		if(x!=y){
			pre[x]=y;
			cnt++;
			ans+=e[i].w;
		}
		if(cnt==n-1){
			break;
		}
	}
	if(cnt==n-1)cout << ans << endl;
	return 0;
}
2024/12/30 00:40
加载中...