题目在这
划水划水,AC如下:
#include<bits/stdc++.h>
#define maxn 305
using namespace std;
const int INF = INT_MAX/100;
int n, m, t, d[maxn][maxn];
void init()
{
cin>>n>>m>>t;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(i == j)
d[i][j] = 0;
else
d[i][j] = INF;
int s,e,h;
for(int i = 0; i < m; i++){
cin>>s>>e>>h;
d[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(d[i][k] < INF && d[k][j] < INF )
d[i][j] = min(d[i][j], max(d[i][k], d[k][j]));
}
int main()
{
init();
floyd();
/*
for(int i = 1; i <= n ;i++){
for(int j =1; j <= n; j++){
if(j != 1) cout<<' ';
cout<<d[i][j];
}
cout<<endl;
}*/
int a,b;
while(t--){
cin>>a>>b;
if(d[a][b] == INF)
cout<<-1<<endl;
else
cout<<d[a][b]<<endl;
}
return 0;
}