标签:space pre map ffffff stream cout ble mes lan
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int minn(int x,int y)
{
return x<y?x:y;
}
int tot,m,a,b,num[101],n,map[101][101];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
map[i][j]=10000000;
for(int i=1;i<=n;i++)
{
cin>>num[i]>>a>>b;
if(a)map[i][a]=map[a][i]=1;
if(b)map[i][b]=map[b][i]=1;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
map[i][j]=minn(map[i][j],map[i][k]+map[k][j]);
m=0x7fffffff;
for(int i=1;i<=n;i++)
{
tot=0;
for(int j=1;j<=n;j++)
if(i!=j)
tot+=map[i][j]*num[j];
if(tot<m)
m=tot;
}
cout<<m;
}
标签:space pre map ffffff stream cout ble mes lan
原文地址:https://www.cnblogs.com/JCRL/p/10063567.html