---

# Audiophobia

UVa 10048

#include <stdio.h>
#define INF 100000005
const int maxn = 105;
int map[maxn][maxn], n, m;
void init ( )
{
for ( int i = 0; i <= n; i ++ ) //初始化,只有起点终点一样时为0
for ( int j = 0; j <= n; j ++ )
map[i][j] = i == j ? 0 : INF;
}
inline int Max ( int a, int b )
{
return a > b ? a : b;
}
inline int Min ( int a, int b )
{
return a < b ? a : b;
}
void floyd ( )
{
for ( int k = 1; k <= n; k ++ )
for ( int i = 1; i <= n; i ++ )
for ( int j = 1; j <= n; j ++ )
map[i][j] = Min ( map[i][j], Max ( map[i][k], map[k][j] ) );
//求间接路径的最大值 在求最小值
}
int main ( )
{
int q, cas = 0, u, v, l;
while ( ~ scanf ( "%d%d%d", &n, &m, &q ) && ( n || m || q ) )
{
init ( );
while ( m -- )
{
scanf ( "%d%d%d", &u, &v, &l );
if ( map[u][v] > l )    //有可能存在同一段都有值
map[u][v] = map[v][u] = l;
}
if ( cas ++ )
printf ( "\n" );
printf ( "Case #%d\n", cas );
floyd ( );
while ( q -- )
{
scanf ( "%d%d", &u, &v );
if ( map[u][v] >= INF ) //超过最大值证明没有最短路
printf ( "no path\n" );
else
printf ( "%d\n", map[u][v] );
}
}
return 0;
}


10-12 1334

05-19 543

09-18 2299

06-07 423

04-21 236

07-18 223

03-15 467

05-23 538

03-11 131

03-03 365