1. C++, Tobias Fuchs


/*
* Author: Tobias Fuchs
* Problem: 10048 (Audiophobia)
* Verdict: Accepted
* Runtime: 0.040
*
*/

#include<stdlib.h>
#include<stdio.h>
#include<string.h>

#define INFTY 0xffff
#define MIN(a,b) ((a) > (b)? (b):(a))
#define MAX(a,b) ((a) > (b)? (a):(b))

#define logn(msg, n) printf(msg " %d\n", n)

int A[100][100];

void floyd(int num)
{
int i, j, k;
for(k = 1; k <= num; k ++) {
for(i = 1; i <= num; i++) {
for(j = 1; j <= num; j++) {
A[i][j] = MIN( A[i][j], MAX(A[i][k], A[k][j]) );
}
}
}
}

int main()
{
int i, j, id_a, id_b, val, crossings, streets, queries, from, to;
int n_cases = 1;

while(scanf("%d%d%d", &crossings, &streets, &queries) == 3)
{
if(!crossings && !streets && !queries) break;

for(i = 1; i <= crossings; i++) {
for(j = 1; j <= crossings; j++) { A[i][j] = INFTY; }
A[i][i] = 0;
}

for(i = 0; i < streets; i++) {
scanf("%d%d%d", &id_a, &id_b, &val);
A[id_a][id_b] = val;
A[id_b][id_a] = val;
}

if(n_cases > 1) { putchar('\n'); }
printf("Case #%d\n", n_cases++);

floyd(crossings);
while(queries--) {
scanf("%d%d", &from, &to);
if(A[from][to] == INFTY) {
printf("no path\n");
}
else {
printf("%d\n", A[from][to]);
}
}
}
return 0;
}