P2888?[USACO07NOV]Cow Hurdles Shttps://www.luogu.com.cn/problem/P2888
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
#include <deque>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
int n, m, t;
int s[450][450];
int main() {
for (int i = 1; i <= 350; i++) {
for (int j = 1; j <= 350; j++) {
s[i][j] = INF;
}
}
int x, y, c;
scanf("%d %d %d", &n, &m, &t);
for (int i = 1; i <= m; i++) {
scanf("%d %d %d", &x, &y, &c);
s[x][y] = c;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
s[i][j] = min(s[i][j], max(s[i][k], s[k][j]));
}
}
}
while (t--) {
scanf("%d %d", &x, &y);
if (s[x][y] != INF) {
printf("%d\n", s[x][y]);
} else {
printf("-1\n");
}
}
return 0;
}
|