题目描述

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.

  奶牛们为了比赛要刻苦训练跳木桩。现在有n个木桩,并知道其中m对木桩的高度差。问奶牛们能从木桩u跳到木桩v,最少的跳跃高度是多少?

输入输出格式

输入格式:

  • 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

输出格式:

  • 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.

输入输出样例

输入样例#1:

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
输出样例#1:

4
8
-1

裸floyd

有个坑点是,跳柱子还神tm是单向的……

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int mp[mxn][mxn];
int n,m,T;
int main(){
n=read();m=read();T=read();
int i,j;
int u,v,d;
memset(mp,0x3f,sizeof mp);
for(i=;i<=m;i++){
u=read();v=read();d=read();
mp[u][v]=min(mp[u][v],d);
}
for(int k=;k<=n;++k)
for(i=;i<=n;++i)
for(j=;j<=n;++j)
mp[i][j]=min(mp[i][j],max(mp[i][k],mp[k][j]));
while(T--){
u=read();v=read();
if(mp[u][v]==0x3f3f3f3f)printf("-1\n");
else printf("%d\n",mp[u][v]);
}
return ;
}

洛谷P2888 [USACO07NOV]牛栏Cow Hurdles的更多相关文章

  1. 洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles

    题目戳 题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the ...

  2. bzoj1641 / P2888 [USACO07NOV]牛栏Cow Hurdles

    P2888 [USACO07NOV]牛栏Cow Hurdles Floyd $n<=300$?果断Floyd 给出核心式,自行体会 $d[i][j]=min(d[i][j],max(d[i][k ...

  3. Luogu P2888 [USACO07NOV]牛栏Cow Hurdles

    题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gan ...

  4. [USACO07NOV]牛栏Cow Hurdles

    OJ题号:洛谷2888 思路:修改Floyd,把边权和改为边权最大值.另外注意是有向图. #include<cstdio> #include<algorithm> using ...

  5. 洛谷P2886 [USACO07NOV]牛继电器Cow Relays

    题意很简单,给一张图,把基本的求起点到终点最短路改成求经过k条边的最短路. 求最短路常用的算法是dijkstra,SPFA,还有floyd. 考虑floyd的过程: c[i][j]=min(c[i][ ...

  6. 洛谷 P2886 [USACO07NOV]牛继电器Cow Relays

    题面 解题思路 ## floyd+矩阵快速幂,跟GhostCai爷打赌用不用离散化,最后完败..GhostCai真是tql ! 有个巧妙的方法就是将节点重新编号,因为与节点无关. 代码 #includ ...

  7. 洛谷P2886 [USACO07NOV]Cow Relays G (矩阵乘法与路径问题)

    本题就是求两点间只经过n条边的最短路径,定义广义的矩阵乘法,就是把普通的矩阵乘法从求和改成了取最小值,把内部相乘改成了相加. 代码包含三个内容:广义矩阵乘法,矩阵快速幂,离散化: 1 #include ...

  8. 洛谷 P2887 [USACO07NOV]防晒霜Sunscreen 解题报告

    P2887 [USACO07NOV]防晒霜Sunscreen 题目描述 To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2 ...

  9. 洛谷P1472 奶牛家谱 Cow Pedigrees

    P1472 奶牛家谱 Cow Pedigrees 102通过 193提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 农民约翰准备 ...

随机推荐

  1. windows8.1专业版 关闭ie11总是已停止工作

    该问题通常原因: 1 系统重病毒: 2 系统和安装的软件不兼容导致. 解决方案: 1 杀毒更新至最新进行杀毒,仍未解决,重新安装系统: 2 目前身边人员多数属于该情况: 1 如安装了输入法.迅雷或其它 ...

  2. android开发学习——Socket发送和接收

    client -- server发送过程中,涉及的输入流输出流: http://blog.csdn.net/dlwh_123/article/details/35982015   (良心好文)   需 ...

  3. HTML5的音频播放和视频播放

    1.音频播放 audio(音频) html5提供了播放音频文件的标准   <audio src="anli.mp3" controls="controls" ...

  4. 转载:如何使用RFT自动打开IE

    如何在RFT测试脚本中打开IE浏览器?   第一步,配置应用程序进行测试: “配置”菜单 ——> “配置应用程序进行测试...”,进入下面这个界面,默认三个自带的应用程序,点击“添加”加入IE. ...

  5. 什么是BDD?

    BDD是TDD的一种衍生,通过特定的BDD框架,用自然语言或类自然语言,按照编写用户故事或者用户用例的方式,以功能使用者的视角,描述并编写测试用例. BDD源于TDD并优于测试驱动开发. 之所以说BD ...

  6. CAD交互绘制虚线(com接口)

    用户可以在控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY ...

  7. 【经验】停止Smart Card服务

    Windows+R键调出运行 输入 services.msc 有一项Smart Card的服务找到他->属性->启动类型(设置为禁用 )->确定,然后重新启动服务

  8. 初始化react项目

    react脚手架 npm install -g create-react-app 国内npm一般下载比较慢或者是常出现下载失败的情况,我们可以指定下载的仓库: npm install -g creat ...

  9. Java中List集合的遍历

    一.对List的遍历有三种方式 List<String> list = new ArrayList<String>(); list.add("testone" ...

  10. jQuery-鼠标经过显示大图并跟随鼠标效果方法封装

    //copyright c by zhangxinxu 2019-1-15 /*由于大图绑定在href属性中,故一般而言,需使用a标签的href指向大图.仅支持png,gif,jpg,bmp四种格式的 ...