n^2f复杂度
生成单点
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> #include<queue> #include<math.h> using namespace std; int n,way[120][120],minn[120],t[120],ans=0; int main() { freopen("WIRE.IN","r",stdin); freopen("WIRE.OUT","w",stdout); int x; scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { scanf("%d",&x); way[i][j]=x; } memset(minn,127,sizeof(minn)); minn[1]=0; for(int i=1;i<=n;i++) { int k=0; for(int j=1;j<=n;j++) if((!t[j])&&minn[j]<minn[k]) k=j; t[k]=1; for(int j=1;j<=n;j++) if(!t[j]) minn[j]=min(minn[j],way[k][j]); } for(int i=1;i<=n;i++) ans+=minn[i]; cout<<ans; return 0; }