看仔细我的代码我都笑了
#include <bits/stdc++.h>
using namespace std;
const int N=1e5*5+10;
struct j{
int a,b,c;
}q[N];
int p[N];
int find(int x){
if(p[x]==x)return x;
return p[x]=find(p[x]);
}
int main(){
int n,m=0;
cin>>n>>m;
int w=1;
for(int x=1;x<=m;x++)q[w++]={0,x,n};
for(int x=1;x<=m;x++)p[x]=x;
for(int x=1;x<=m;x++){
for(int y=1;y<=m;y++){
q[w].a=x,q[w].b=y;
cin>>q[w].c;
if(q[w].c==0)q[w].c=n;
w++;
}
}
sort(q+1,q+w,[](j x,j y){return x.c<y.c;});
long long sum=0;
for(int x=1;x<w;x++){
if(find(q[x].a)!=find(q[x].b)){
p[find(q[x].b)]=find(q[x].a);
sum+=q[x].c;
}
}
cout<<sum;
return 0;
}