题目:Path and Wall
或者在vjudge上:Path and Wall
分析:floyd即可,DFS找最短会TLE
#include <iostream>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<queue>
#include<math.h>
#include<stack>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<iostream>
using namespace std;
#define MAX 0x3f3f3f3f
typedef long long ll;
int n,m,k;
int road[105][105];
void floyd()
{
for(int k = 1; k <= n ;k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n ;j++)
{
int mmax = max(road[i][k], road[k][j]);
if(mmax < road[i][j])
road[i][j] = mmax;
}
}
}
}
int main()
{
int t = 1;
while(1)
{
cin>>n>>m>>k;
if(n==0&&m==0&&k==0)
break;
memset(road,MAX,sizeof(road));
if(t != 1)
cout<<endl;
while(m--)
{
int a,b,c;
cin>>a>>b>>c;
road[a][b] = road[b][a] = c;
}
floyd();
cout<<"Case #"<<t<<endl;
while(k--)
{
int a,b;
cin>>a>>b;
if(road[a][b] == MAX)
cout<<"no path\n";
else
cout<<road[a][b]<<endl;
}
t++;
}
return 0;
}