Cow Hurdles

Time Limit: 1000MS Memory Limit: 65536K

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: N, M, 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

题意:给与点和边,然后询问任意两点间的距离。若无法到达则输出-1

题解:用最暴力的Floyed算法求出所有点的最短路,然后根据询问输出就可以了。

#include <queue>
#include <cmath>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> using namespace std; const int maxn = 255;
const int INF = 1e9 + 7; int s[maxn][maxn]; int main()
{
int m,n,i,j,k,t,a,b,c;
scanf("%d%d%d",&n,&m,&t);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
s[i][j] = i==j?0:INF;
for(i=0;i<m;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(s[a][b]>c)
s[a][b] = c;
}
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(max(s[i][k],s[k][j])<s[i][j])
s[i][j] = max(s[i][k],s[k][j]);
}
while(t--)
{
scanf("%d%d",&a,&b);
if(s[a][b]==INF)
printf("-1\n");
else
printf("%d\n",s[a][b]);
}
return 0;
}

POJ-3615_Cow Hurdles的更多相关文章

  1. POJ 3615 Cow Hurdles

    http://poj.org/problem?id=3615 floyd 最短路径的变形 dist[i][j]变化为 : i j之间的最大边 那么输入的时候可以直接把dist[i][j] 当作i j ...

  2. POJ 3615 Cow Hurdles(最短路径flyod)

    Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9337   Accepted: 4058 Descr ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. 图论常用算法之一 POJ图论题集【转载】

    POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...

  5. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  6. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  7. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  8. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  9. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  10. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. draft.js开发富文本编辑器

    写在前头的话 在react中去寻找一个好用的富文本编辑器网上很少有推荐的,搜到的也只有一些个人不成熟的作品,慢慢发现网上比较推荐的一个东东叫做draft.js. 这个东西在网上可以找到的教程也是手指头 ...

  2. git学习记录——分支管理和多人协作

    在公司里难免会出现多个人一起工作,这就需要构建多个分支派发给多个人去干活 这就产生一个需求,分支管理 分支的创建,合并和删除 其他版本控制系统如SVN等都有分支管理,但是用过之后你会发现,这些版本控制 ...

  3. hdu 1166 敌兵布阵(线段树区间求和)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. 索尼微单cmos坏点屏蔽

    偶然发现相机有坏点了,果断去售后换了一台回来.然后试机,吐血 要不是我旧机器满是岁月的痕迹,我真以为原封给我退回来了 这样不行啊,难道再换一个回来?毕竟是脸皮薄的人.不好意思操作啊. 于是上网找找,果 ...

  5. php的FTP操作类

    class_ftp.php <?php /** * 作用:FTP操作类( 拷贝.移动.删除文件/创建目录 ) */ class class_ftp { public $off; // 返回操作状 ...

  6. CF573E (平衡树)

    CF573E 题意概要 给出一个长度为\(n\)的数列,从中选出一个子序列\(b[1...m]\)(可以为空) 使得\[ \sum_{i=1}^m{b_i*i}\]最大,输出这个最大值. 其中\(n\ ...

  7. IntelliJ IDEA中设置同时打开多个文件且分行显示

    [转载]原文链接:https://blog.csdn.net/lwl20140904/article/details/73275897 有时候要是打开多个文件,要么都显示在一行,要么因为空间不足,就给 ...

  8. Django快速创建新项目

    Python免费视频含配套文件QQ124111294 https://pan.baidu.com/s/1bL5ml4 python.exe manage.py startapp app01 pytho ...

  9. pyenv虚拟环境管理python多版本和软件库

    可能大家在日常工作中会遇到这么个问题,现在基本的linux系统都是自带老版本的python2.7.x版本,我又不想用老版本,但直接升级可能会出问题,或是依赖老版本的程序就运行不了,有没办法能安装3.x ...

  10. oracle触发器级联删除

    create or replace trigger delete_trigger1 after delete on contracting_party for each row begin if de ...