Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

floyd

Posted by 2742195759 at 2016-03-26 11:10:56 on Problem 3615
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator