洛谷 2966 2966 [USACO09DEC]牛收费路径Cow Toll Paths

【题意概述】
给出一个图,点有正点权,边有正边权,通过两点的代价为两点间的最短路加上路径通过的点的点权最大值。
有M个询问,每次询问通过两点的代价。
【题解】
先把点按照点权从小到大排序,然后按照这个顺序跑floyed. 这样的话当前路径i-->k-->j的点权最大值只会在i,j,k中产生,用一个ans[i][j]数组维护代价即可。
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
#define rg register
#define N 300
using namespace std;
int n,m,q,f[N][N],ans[N][N],poi[N];
struct rec{
int c,num;
}a[N];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline void Pre(){
for(rg int i=;i<=n;i++)
for(rg int j=;j<=n;j++) f[i][j]=ans[i][j]=1e9;
for(rg int i=;i<=n;i++) f[i][i]=ans[i][i]=;
}
inline int mx(int a,int b,int c){
int t=-2e9;
if(a>t)t=a;
if(b>t)t=b;
if(c>t)t=c;
return t;
}
inline bool cmp(rec a,rec b){return a.c<b.c;}
int main(){
n=read(); m=read(); q=read();
Pre();
for(rg int i=;i<=n;i++) a[i].c=read(),a[i].num=i;
sort(a+,a++n,cmp);
for(rg int i=;i<=m;i++){
int u=read(),v=read();
f[u][v]=f[v][u]=min(f[u][v],read());
}
for(rg int k=;k<=n;k++)
for(rg int i=;i<=n;i++)
for(rg int j=;j<=n;j++){
int K=a[k].num,I=a[i].num,J=a[j].num;
f[I][J]=f[J][I]=min(f[I][J],f[I][K]+f[K][J]);
ans[I][J]=ans[J][I]=min(ans[I][J],f[I][J]+mx(a[i].c,a[j].c,a[k].c));
}
while(q--){
int u=read(),v=read();
printf("%d\n",ans[v][u]);
}
return ;
}
洛谷 2966 2966 [USACO09DEC]牛收费路径Cow Toll Paths的更多相关文章
- P2966 [USACO09DEC]牛收费路径Cow Toll Paths
P2966 [USACO09DEC]牛收费路径Cow Toll Paths 题目描述 Like everyone else, FJ is always thinking up ways to incr ...
- 洛谷 P2966 [USACO09DEC]牛收费路径Cow Toll Paths
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...
- Luogu P2966 [USACO09DEC]牛收费路径Cow Toll Paths
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...
- [USACO09DEC]牛收费路径Cow Toll Paths
跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道路行走,都 要向农夫约翰上交过路费. 农场中 ...
- [Luogu P2966][BZOJ 1774][USACO09DEC]牛收费路径Cow Toll Paths
原题全英文的,粘贴个翻译题面,经过一定的修改. 跟所有人一样,农夫约翰以宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道 ...
- [USACO09DEC]牛收费路径Cow Toll Paths(floyd、加路径上最大点权值的最短路径)
https://www.luogu.org/problem/P2966 题目描述 Like everyone else, FJ is always thinking up ways to increa ...
- 【[USACO09DEC]牛收费路径Cow Toll Paths】
很妙的一道题,我之前一直是用一个非常暴力的做法 就是枚举点权跑堆优化dijkstra 但是询问次数太多了 于是一直只有50分 今天终于抄做了这道题,不贴代码了,只说一下对这道题的理解 首先点权和边权不 ...
- 洛谷P1522 [USACO2.4]牛的旅行 Cow Tours
洛谷P1522 [USACO2.4]牛的旅行 Cow Tours 题意: 给出一些牧区的坐标,以及一个用邻接矩阵表示的牧区之间图.如果两个牧区之间有路存在那么这条路的长度就是两个牧区之间的欧几里得距离 ...
- 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
随机推荐
- 使用IntelliJ IDEA 创建Maven项目(入门)
一. 下载Maven 下载地址:http://maven.apache.org/download.cgi tar.gz压缩格式用于unix操作系统,而zip用于windows的操作系统,但在windo ...
- bzoj 1621: [Usaco2008 Open]Roads Around The Farm分岔路口【dfs】
模拟就行--讲道理这个时间复杂度为啥是对的??? #include<iostream> #include<cstdio> using namespace std; int k, ...
- 微信小程序获取自定义属性值
写小程序的时候用到了自定义属性,特地来记录一下 特别是这个坑,必须得说一说 wxml <view class='box' bindtap='getValue'> <view clas ...
- E - A^B mod C (大数乘方取模)
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63) ...
- ACM_蛇形矩阵
蛇行矩阵 Time Limit: 4000/2000ms (Java/Others) Problem Description: 蛇形矩阵是由1开始的自然数依次排列成的一个矩阵上三角形. Input: ...
- oracle 自定义类型 type / create type
一:Oracle中的类型有很多种,主要可以分为以下几类: 1.字符串类型.如:char.nchar.varchar2.nvarchar2. 2.数值类型.如:int.number(p,s).integ ...
- 【JAVA 学习笔记2】if使用例子
int a =3; if (a%2==0) { System.out.println(a+" 是偶数"); System.out.println(a+" 不是奇数&quo ...
- ubuntu下删除和新建用户(并有su权限)
http://blog.csdn.net/speedme/article/details/8206144ubuntu下删除和新建用户(并有su权限) 如何创建ubuntu新用户?输入:sudo add ...
- jQuery.fn.extend和jQuery.extend
<script src="http://www.cssrain.cn/demo/JQuery+API/jquery-1[1].2.1.pack.js" type=" ...
- 字符编码方式ASCII、Unicode、UTF-8
一.ASCII 1.介绍 即American Standard Code for Information Interchange(美国信息交换标准代码),是基于拉丁字母的,主要用于显示现代英语和其他西 ...