【POJ 3615】Cow Hurdles

Cow Hurdles

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6486   Accepted: 2948

Description

Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are getting tired, though, so they want to be able to use as little energy as possible to jump over the hurdles.

Obviously, it is not very difficult for a cow to jump over several very short hurdles, but one tall hurdle can be very stressful. Thus, the cows are only concerned about the height of the tallest hurdle they have to jump over.

The cows‘ practice room has N (1 ≤ N ≤ 300) stations, conveniently labeled 1..N. A set of M (1 ≤ M ≤ 25,000) one-way paths connects pairs of stations; the paths are also conveniently labeled 1..M. Path i travels from station Si to station Ei and contains exactly one hurdle of height Hi (1 ≤ Hi ≤ 1,000,000). Cows must jump hurdles in any path they traverse.

The cows have T (1 ≤ T ≤ 40,000) tasks to complete. Task i comprises two distinct numbers, Ai and Bi (1 ≤ Ai ≤ N; 1 ≤ Bi ≤ N), which connote that a cow has to travel from station Ai to station Bi (by traversing over one or more paths over some route). The cows want to take a path the minimizes the height of the tallest hurdle they jump over when traveling from Ai to Bi . Your job is to write a program that determines the path whose tallest hurdle is smallest and report that height.
 

Input

* Line 1: Three space-separated integers: NM, and T
* Lines 2..M+1: Line i+1 contains three space-separated integers: Si , Ei , and Hi 
* Lines M+2..M+T+1: Line i+M+1 contains two space-separated integers that describe task i: Ai and Bi

Output

* Lines 1..T: Line i contains the result for task i and tells the smallest possible maximum height necessary to travel between the stations. Output -1 if it is impossible to travel between the two stations.

Sample Input

5 6 3
1 2 12
3 2 8
1 3 5
2 5 3
3 4 4
2 4 8
3 4
1 2
5 1

Sample Output

4
8
-1

Source

USACO 2007 November Silver

裸的传递闭包啊啊啊。

醉了。。。不说了。我想静静。

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const int MAXN = 305;

int dis[MAXN][MAXN];
int n;
int m;
int t;

int main()
{
    memset(dis, 0x7f, sizeof(dis));
    scanf("%d%d%d", &n, &m, &t);
    for (int i = 0; i < m; ++i)
    {
        int u;
        int v;
        int w;
        scanf("%d%d%d", &u, &v, &w);
        dis[u][v] = min(dis[u][v], w);
    }
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            if (k != i)
                for (int j = 1; j <= n; ++j)
                    if (k != j && i != j) dis[i][j] = min(dis[i][j], max(dis[i][k], dis[k][j]));
    while (t--)
    {
        int u;
        int v;
        scanf("%d%d", &u, &v);
        if (dis[u][v] > 1000000) printf("-1\n");
        else printf("%d\n", dis[u][v]);
    }
    return 0;
}
时间: 2024-08-02 22:47:13

【POJ 3615】Cow Hurdles的相关文章

【POJ 3167】Cow Patterns (KMP+树状数组)

Cow Patterns Description A particular subgroup of K (1 <= K <= 25,000) of Farmer John's cows likes to make trouble. When placed in a line, these troublemakers stand together in a particular order. In order to locate these troublemakers, FJ has lined

【POJ 3176】Cow Bowling

题 Description The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this: 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 Then the other cows travers

【POJ 3270】Cow Sorting(置换群排序)

Cow Sorting(置换群排序) Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6909 Accepted: 2716 Description Farmer John's N (1 ≤ N ≤ 10,000) cows are lined up to be milked in the evening. Each cow has a unique "grumpiness" level in the range 1

【POJ 3267】 The Cow Lexicon

[POJ 3267] The Cow Lexicon 训练计划里把这题排到了topo里....然后我就这么死盯研究了一周topo算法(期间经历了三个人生风波....大物考试 高数考试跟模电考试----)啥不说了--上dp代码----没错 这是个dp!...赤果果的dp..就呢么傻呆呆地研究Topo算法--结果没研究出来.. 题意是给一个字符串和m个单词组成的字典,问最少删除几个字母能让这个字符串变成由字典中几个单词首位链接组成的字符串 dp思路还算好想 逆推 dp数组的下标是遍历字符串的起点 然

【POJ 1408】 Fishnet (叉积求面积)

[POJ 1408] Fishnet (叉积求面积) 一个1*1㎡的池塘 有2*n条线代表渔网 问这些网中围出来的最大面积 一个有效面积是相邻两行和相邻两列中间夹的四边形 Input为n 后面跟着四行 每行n个浮点数 每一行分别代表a,b,c,d 如图 并且保证a(i) > a(i-1) b(i) > b(i-1) c(i) > c(i-1) d(i) > d(i-1) n(n <= 30)*2+4(四个岸)条边 枚举点数就行 相邻的四个四个点枚举 找出围出的最大面积 找点用

【POJ 2513】Colored Sticks

[POJ 2513]Colored Sticks 并查集+字典树+欧拉通路 第一次做这么混的题..太混了-- 不过题不算难 字典树用来查字符串对应图中的点 每个单词做一个点(包括重复单词 题意就是每个边走且直走一次(欧拉通路 欧拉图的判定: 没有或者只有两个奇数度的点的图叫做欧拉图 有这些就可以解答此题了 另外需要注意题目范围是25W个木棍 所以最多可能有50W个点 卡了好多个RE 代码如下: #include <iostream> #include <cstdlib> #incl

2292: 【POJ Challenge 】永远挑战

2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 553  Solved: 230[Submit][Status][Discuss] Description lqp18_31和1tthinking经常出题来虐ftiasch.有一天, lqp18_31搞了一个有向图,每条边的长度都是1. 他想让ftiasch求出点1到点 N 的最短路."水题啊.", ftiasch这么说道. 所以1tth

【POJ 1201】 Intervals(差分约束系统)

[POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 23817   Accepted: 9023 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p

【POJ 1228】Grandpa&#39;s Estate 凸包

找到凸包后暴力枚举边进行$check$,注意凸包是一条线(或者说两条线)的情况要输出$NO$ #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define N 1003 #define read(x) x = getint() using namespace std; inline int getint() { int k = 0, fh = 1; char c