题目描述

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. Java编码格式

    简介 编码问题一直困扰着开发人员,尤其在 Java 中更加明显,因为 Java 是跨平台语言,不同平台之间编码之间的切换较多.本文将向你详细介绍 Java 中编码问题出现的根本原因,你将了解到:Jav ...

  2. android开发学习 ------- 【转】Gradle相关

    一直在用AndroidStudio,但是对于其Gradle了解的很少. 推荐 http://www.jianshu.com/p/9df3c3b6067a  觉得说的很棒!

  3. jquery各种选择器示例

    $("#itemExpressionHidden>b:last")   选择id为itemExpressionHidden中的最后一个b标签 $("#itemExp ...

  4. java获取公网ip以及物理地址和代理商

    package ipconfig; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr ...

  5. Mac 为啥不显示图片尺寸,点了显示简介也不显示~???

    这个问题困扰我好几天,然后今天想法子解决,我这个强迫症患者是真的难受,不能直接一目了然的,每次都要ps打开图片去看,真的好心累???? 网上98%的解决方法如下: 在 Finder 中,按快捷键 co ...

  6. kubernetesV1.13.1一键部署脚本(k8s自动部署脚本)

    部署k8sv1.13.1只需要下面几步就OK了: git clone https://github.com/luckman666/deploy_Kubernetes-v1.13.1.git cd de ...

  7. Cannot load php5apache2_4.dll into server 问题的解决方法

    解决方法,重新安装 VC9或 VC11 试试,或者全部安装VC9  VC11 注意:如果下载的 php5.5为32位版本, 那么安装的vc9或VC11 也必须是32位版本.           如果下 ...

  8. Android SDK镜像更新网速慢的解决问题

    通过更换代理解决 Android SDK 在线更新镜像服务器资源:大连东软信息学院镜像服务器地址:http://mirrors.neusoft.edu.cn 端口:80北京化工大学镜像服务器地址:IP ...

  9. R in action读书笔记(3)-第六章:基本图形

    第六章  基本图形 6.1条形图 条形图通过垂直的或水平的条形展示了类别型变量的分布(频数).函数:barplot(height) 6.1.1简单的条形图 6.1.2推砌条形图和分组条形图 如果hei ...

  10. vba根据部门分别汇总不同部门下的人员不同培训内容的时长总计,多条件求和

    Option Explicit Sub yy() Dim d, arr, s$, i&, m&, w$ Set d = CreateObject("Scripting.Dic ...