标签:inf else span main out amp col end max
#include<bits/stdc++.h> using namespace std; const int maxN=110; const int inf=1e8; map<string,int> id; int dis[maxN][maxN]; int main(){ for(int i=0;i<maxN;i++){ for(int j=0;j<maxN;j++)dis[i][j]=inf; dis[i][i]=0; } int m,n,d,cnt=0,u,v; cin>>m>>n; string a,b; while(n--){ cin>>a>>b>>d; if(!id.count(a))id[a]=++cnt,u=cnt; else u=id[a]; if(!id.count(b))id[b]=++cnt,v=cnt; else v=id[b]; if(dis[u][v]>d)dis[u][v]=dis[v][u]=d; } for(int k=1;k<=cnt;k++){ for(int i=1;i<=cnt;i++){ for(int j=1;j<=cnt;j++)if(dis[i][j]>dis[i][k]+dis[k][j]){ dis[i][j]=dis[i][k]+dis[k][j]; } } } cin>>n; while(n--){ cin>>a>>b; if(id.count(a)==1&&id.count(b)==1)cout<<(dis[id[a]][id[b]]<inf?dis[id[a]][id[b]]:-1)<<endl; else cout<<-1<<endl; } }
标签:inf else span main out amp col end max
原文地址:https://www.cnblogs.com/TAMING/p/9286502.html