poj 3615 Cow Hurdles

原创 2012年03月25日 18:51:29

赤裸裸的floyd,思路很直接。很容易想到。

/*
POJ: 3615 Cow Hurdles
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

#define MaxN 305
#define MaxD (1 << 20)
        
using namespace std;

long map[MaxN][MaxN];
int n, m, t;

void solve()
{
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            for(int k = 1; k <= n; k++)
                map[j][k] = min(map[j][k], max(map[j][i], map[i][k]));    
}
            
int main()
{
    //freopen("data.in", "rb", stdin);
    while(scanf("%d%d%d", &n, &m, &t) != EOF) {
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= n; j++) {
                map[i][j] = MaxD;
            }
        }
        
        for(int i = 0; i < m; i++) {
            int a, b;
            long c;
            scanf("%d%d%ld", &a, &b, &c);
            map[a][b] = c;
        }
        
        solve();
        
        for(int i = 0; i < t; i++) {
            int a, b;
            scanf("%d%d", &a, &b);
            if(map[a][b] < MaxD)
                printf("%d\n", map[a][b]);
            else
                printf("-1\n");
        }
    }
    
    return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

[floyd]POJ 3615 Cow Hurdles

传送门:Cow Hurdles Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Sub...

POJ 3615 Cow Hurdles.

Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie a...

poj 3615 Cow Hurdles

poj 3615 Cow Hurdles

POJ 3615 Cow Hurdles(Folyd变形)

POJ 3615 Cow Hurdles(Folyd变形) http://poj.org/problem?id=3615 题意:给你一个有向图,然后对于特定的点A与B,要你求出A到B之间所有可行路径的...

poj 3615(Cow Hurdles) floy 算法

Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4082   Ac...

POJ3615 - Cow Hurdles - 最短路

1.题目描述: Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions...

POJ--3615|Cow Hurdles

Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7699   Ac...

POJ 3615 Cow Hurdles Floyd算法的变体

http://poj.org/problem?id=3615题意:找一条最短路径,并求出这条路径上任意两个节点之中的最大路径长度实际上就是Floyd算法,只不过这里不是求的最短路径长度,而是最短路径上...

POJ - 3615 Cow Hurdles (Floyd变形)

Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are...

poj 3615 Cow Hurdles

Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5214   Ac...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)