| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
floyd#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#define inf 0x3f3f3f3f
#define mem0(x , y) memset(x , y , sizeof(x))
#define ll long long
using namespace std;
int g[400][400] ;
int main(){
///freopen("1" , "r" ,stdin) ;
mem0(g , inf) ;
for(int i=0;i<400;i++){
g[i][i] = 0 ;
}
int n , m , k ;
int ta,tb,tc ;
scanf("%d%d%d",&n,&m,&k) ;
for(int i=0;i<m;i++){
scanf("%d%d%d",&ta,&tb,&tc) ;
g[ta][tb] = min(g[ta][tb] , tc) ;
}
for(int z=1;z<=n;z++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)if(i != j && g[i][z] != inf && g[z][j] != inf ){
g[i][j] = min(g[i][j] , max(g[i][z] , g[z][j])) ;
}
}
}
for(int i=0;i<k;i++){
scanf("%d%d",&ta,&tb) ;
if(g[ta][tb] == inf) printf("-1\n") ;
else printf("%d\n",g[ta][tb]) ;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator