#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =500;int n;int dist[N], g[N][N];bool st[N];intprim(){memset(dist,0x3f,sizeof(dist));
dist[1]=0;int res =0;for(int i =0; i < n; i ++){int t =-1;for(int j =1; j <= n ;j ++){if(!st[j]&&(t ==-1|| dist[t]> dist[j]))
t = j;}
res += dist[t];
st[t]=true;for(int j =1; j <= n ; j ++){
dist[j]=min(dist[j], g[t][j]);}}return res;}intmain(){
cin >> n;for(int i =1; i <= n; i ++){for(int j =1; j <= n; j ++){
cin >> g[i][j];}}
cout <<prim()<< endl;}
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =200;int n, k, g[N][N], st[N], dist[N];int ans =0;intprim(){memset(dist,0x3f,sizeof(dist));
dist[1]=0;int res =0;for(int i =0; i < n; i ++){int t =-1;for(int j =1; j <= n ;j ++){if(!st[j]&&(t ==-1|| dist[t]> dist[j]))
t = j;}if(dist[t]!=0x3f3f3f3f)
res += dist[t];
st[t]=true;for(int j =1; j <= n ; j ++){
dist[j]=min(dist[j], g[t][j]);}}return res;}intmain(){memset(g,0x3f,sizeof g);scanf("%d%d",&n,&k);for(int i =0; i <= n; i ++)g[i][i]=0;for(int i =0; i < k; i ++){int x1, x2, z;scanf("%d%d%d",&x1,&x2,&z);
g[x1][x2]= g[x2][x1]= z;
ans += z;}printf("%d\n",ans -prim());return0;}
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =500, M =8005;int fa[N], n;struct rec{int x,y,z;}edge[M];booloperator<(rec a,rec b){return a.z<b.z;}intfind(int x){if(fa[x]== x)return x;return fa[x]=find(fa[x]);}intmain(){int m;scanf("%d%d",&n,&m);for(int i =0; i < m ; i ++)scanf("%d%d%d",&edge[i].x,&edge[i].y,&edge[i].z);sort(edge, edge + m);for(int i =1; i <= n; i ++) fa[i]= i;int tot =0, ans =0;for(int i =0; i < m; i ++){int tx =find(edge[i].x);int ty =find(edge[i].y);if(tx == ty)continue;
fa[tx]= ty;
ans =max(ans, edge[i].z);
tot ++;if(tot == n -1)break;}printf("%d %d\n",n -1, ans);return0;}