POJ 3615

#include #include #include #include #include #include #include #include #include #define MAXN 305 #define MAXM 100005 #define MOD 10000 #define inf 10000000 #define eps 1e-9 #define pi acos(-1.0) #define LL long long #define I64 __int64 using namespace std; int n, m, t; int mat[MAXN][MAXN]; int s, e, h; void floyd() { for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (mat[i][k] == inf || mat[k][j] == inf) continue; mat[i][j] = min (mat[i][j], max(mat[i][k], mat[k][j])); } } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt", "w", stdout); while (scanf ("%d %d %d", &n, &m, &t) != EOF) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) mat[i][j] = inf; mat[i][i] = 0; } while (m--) { scanf ("%d %d %d", &s, &e, &h); mat[s][e] = h; } floyd(); while (t--) { scanf ("%d %d", &s, &e); if (mat[s][e] == inf) puts("-1"); else printf ("%d\n", mat[s][e]); } } return 0; }

posted on 2012-11-28 13:54  Sure_Yi  阅读(114)  评论(0编辑  收藏  举报

导航