The Application of Floyd modifies the judgment conditions, but it is not initialized. It begins to ignore a special situation where there is no direct link between the two points and is indirectly linked together.
CIN is really slow!
Code:
# Include <iostream> <br/> using namespace STD; <br/> int G [301] [301]; <br/> int max (int A, int B) <br/>{< br/> return A> B? A: B; <br/>}< br/> int min (int A, int B) <br/>{< br/> return a <B? A: B; <br/>}< br/> int main () <br/> {<br/> int I, j, k, n, W, m, a, B, test, T; <br/> CIN> N> m> test; <br/> memset (G, 0, sizeof (g )); <br/> for (I = 1; I <= m; I ++) <br/> {<br/> scanf ("% d ", & A, & B, & W); <br/> If (G [a] [B]) <br/> G [a] [B] = min (W, G [a] [B]); <br/> else <br/> G [a] [B] = W; <br/>}< br/> for (k = 1; k <= N; k ++) <br/> for (I = 1; I <= N; I ++) <br/> for (j = 1; j <= N; j ++) <br/> {<br/> If (G [I] [k]> 0 & G [k] [J]> 0) <br/> {<br/> T = max (G [I] [K], G [k] [J]); <br/> If (G [I] [J]> 0) <br/> G [I] [J] = min (G [I] [J], t); <br/> else <br/> G [I] [J] = T; <br/>}< br/> while (test --) <br/>{< br/> scanf ("% d", &, & B); <br/> If (G [a] [B] = 0) <br/> printf ("-1/N "); <br/> else <br/> printf ("% d/N", G [a] [B]); <br/>}< br/> return 0; <br/>}< br/>