Noip2013 freight car transportation, but the data range is much smaller.
In less than S, and AC ..
Of course, I wrote Floyd.
It is too much to write the LCA.
# Include <cstdio> # include <cstring> # include <algorithm> # define n 305 # define INF 0x3f3f3fusing namespace STD; int n, m, Q; int map [N] [N]; int main () {// freopen ("test. in "," r ", stdin); int I, j, k; int A, B, C; scanf (" % d ", & N, & M, & Q); memset (MAP, 0x3f, sizeof (MAP); for (I = 1; I <= m; I ++) {scanf ("% d", & A, & B, & C); map [a] [B] = min (Map [a] [B], c) ;}for (k = 1; k <= N; k ++) for (I = 1; I <= N; I ++) for (j = 1; j <= N; j ++) map [I] [J] = min (Map [I] [J], max (M AP [I] [K], map [k] [J]); for (I = 1; I <= Q; I ++) {scanf ("% d", & A, & B); printf ("% d \ n", map [a] [B] <INF? Map [a] [B]:-1);} return 0 ;}
[Poj3615] cow hurdles is the most short-circuited. If you are using LCA, I will not block you.