#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;
const int INF = 0x3f3f3f3f;
int group1[MAXN];
int group2[MAXN];
int G[MAXN][MAXN];
int n, m, t;
void floyd()
{
for(int k = 1; k <= n; ++k)
{
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
if( (i != j) && (G[i][j] > max(G[i][k], G[k][j])) )
{
G[i][j] = max(G[i][k], G[k][j]);
}
}
}
}
}
void print()
{
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
if( (i != j) )
{
cout << G[i][j] << " ";
}
}
cout << endl;
}
}
int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
ios::sync_with_stdio(false);
memset(G, INF, sizeof(G));
cin >> n >> m >> t;
for(int i = 0; i < m ; ++i)
{
int s, e, h;
cin >> s >> e >> h;
G[s][e] = h;
}
floyd();
//print();
for(int i = 0; i < t; ++i) {
int a, b;
cin >> a >> b;
if(G[a][b] == INF) {
cout << "-1" << endl;
} else {
cout << G[a][b] << endl;
}
}
return 0;
}
蒜头君的训练室(floyd)
猜你喜欢
转载自blog.csdn.net/ccshijtgc/article/details/83176010
今日推荐
周排行