Floyd
#include <stdio.h>#include <string.h>#include <algorithm>#include <string>#include <map>#include <iostream>using namespace STD;intn,m,edge[ -][ -],vis[ -],dist[ -]; Map<string,int>AvoidFloyd () {intI,j,k,t; for(k=1; k<=n; k++) for(i=1; i<=n; i++) for(j=1; j<=n; J + +) {if(edge[i][k]==-1|| edge[k][j]==-1)Continue; T=min (Edge[i][k],edge[k][j]);if(edge[i][j]==-1) edge[i][j]=t;Else if(edge[i][j]<t) edge[i][j]=t; }}intMain () {inti,j,tot,st,ed,cas=0, U,v,w;stringS1,S2; while(~scanf("%d%d", &n,&m)) {memset(Edge,0,sizeof(Edge));if(n==0&&m==0) Break; A.clear (); tot=1; for(i=0; i<m; i++) {Cin>>s1>>s2>>w;if(a[s1]==0) {A[s1]=tot; tot++; }if(a[s2]==0) {A[s2]=tot; tot++; } U=A[S1]; V=A[S2]; Edge[u][v]=w; Edge[v][u]=w; } for(i=1; i<=n; i++) for(j=1; j<=n; J + +) {if(edge[i][j]==0) edge[i][j]=-1; }Cin>>s1>>s2; ST=A[S1]; ED=A[S2]; Floyd ();printf("Scenario #%d\n", ++cas);printf("%d tons\n\n", edge[st][ed]); }return 0;}
Dijkstra
cpp
POJ 2263 Heavy Cargo (Floyd+dijkstra)