文章
5
粉丝
0
获赞
0
访问
353
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N =101;
const int inf=0x3f3f3f3f;
int g[N][N];
int cost[N];
bool st[N];
int n;
int prim(){
memset(cost,inf,sizeof cost);
memset(st,0,sizeof st);
int cb=0;
for(int i=0;i<n;i++){
int t=-1;
for(int j=1;j<=n;j++){
if(!st[j]&&(t==-1||cost[t]>cost[j]))t=j;
}
if(i&&cost[t]==inf)return inf;
if(i)cb+=cost[t];
st[t]=1;
for(int j=1;j<=n;j++){
cost[j]=min(cost[j],g[t][j]);
}
}
return cb;
}
int main(){
while(cin>&...
登录后发布评论
暂无评论,来抢沙发