奋斗了两天,终于写过了这道题......

  这道题不仅要求最短路,还要加上路径上最大的点权;

  先用结构体记录点的序号和点的值这是毋庸置疑的;再用另外一个数组来记录当前点权也是可以理解的,毕竟后面要排序;将点权从小到大排序也是为了求最短路;然后再输入每条边的权值;min是为了保证两点之间有重复的边而取最小值;n代表两边的最小值,l就加上了点权;Floyd先将两点相同时就是自己的点权;将点权从小到大枚举,用t来记录此时所对应的原来的序号;两边之间的最短路就用普通的方法,加上点权就要加上中间量k值的点权和两端i,j点权的最大值;最后输出就行了;

#include <bits/stdc++.h>

using namespace std;

inline int read() {
int x = ,ff = ;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') ff = -;
ch = getchar();
}
while(isdigit(ch)) {
x = (x<<) + (x<<) + (ch ^ );
ch = getchar();
}
return x * ff;
} inline void write(int x) {
if(x < ) putchar('-'),x = -x;
if(x > ) write(x / );
putchar(x % + '');
} int a,b,c,m[],n[][],l[][]; struct node {
int id;
int v;
} d[]; bool my(node x,node y) {
return x.v < y.v;
} void Floyd() {
for(int i = ; i <= a; ++i)
l[i][i] = m[i];
for(int k = ; k <= a; ++k) {
int t = d[k].id;
for(int i = ; i <= a; ++i) {
for(int j = ; j <= a; ++j) {
n[i][j] = min(n[i][j],n[i][t] + n[t][j]);
l[i][j] = min(l[i][j],n[i][j] + max(d[k].v,max(m[i],m[j])));
}
}
}
} int main() {
memset(n,0x3f,sizeof(n));
memset(l,0x3f,sizeof(l));
a = read();
b = read();
c = read();
for(int i = ; i <= a; ++i) {
d[i].v = read();
d[i].id = i;
m[i] = d[i].v;
}
sort(d + ,d + a + ,my);
for(int i = ; i <= b; ++i) {
int x,y,v;
x = read();
y = read();
v = read();
n[x][y] = min(n[x][y],v);
n[y][x] = min(n[y][x],v);
}
Floyd();
for(int i = ; i <= c; ++i) {
int x,y;
x = read();
y = read();
write(l[x][y]);
putchar('\n');
} return ;
}

P1218 过路费的更多相关文章

  1. FZU Problem 2082 过路费 树链剖分

    Problem 2082 过路费    Problem Description 有n座城市,由n-1条路相连通,使得任意两座城市之间可达.每条路有过路费,要交过路费才能通过.每条路的过路费经常会更新, ...

  2. Uva 10537 过路费

    题目链接:http://vjudge.net/contest/143062#problem/C 题意: 给定一个无向图,大写字母是城市,小写字母是村庄,经过城市交过路费为当前货物的%5,路过村庄固定交 ...

  3. Floyd | | jzoj[1218] | | [Usaco2009 Dec]Toll 过路费 | | BZOJ 1774 | | 我也不知道该怎么写

    写在前面:老师说这一道题是神题,事实上确实如此,主要是考察对Floyd的理解 ******************************题目.txt************************* ...

  4. 洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib

    P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 284通过 425提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 超时怎么办? ...

  5. Fzu Problem 2082 过路费 LCT,动态树

    题目:http://acm.fzu.edu.cn/problem.php?pid=2082 Problem 2082 过路费 Accept: 528    Submit: 1654Time Limit ...

  6. codevs 1519 过路费 最小生成树+倍增

    /*codevs 1519 过路费 最小生成树+倍增*/ #include<iostream> #include<cstdio> #include<cstring> ...

  7. FZU 2082 过路费(树链剖分)

    FZU 2082 过路费 题目链接 树链抛分改动边的模板题 代码: #include <cstdio> #include <cstring> #include <vect ...

  8. 1774: [Usaco2009 Dec]Toll 过路费

    1774: [Usaco2009 Dec]Toll 过路费 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 263  Solved: 154[Submit ...

  9. BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd

    BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd 题意: 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一 ...

随机推荐

  1. Jenkins系列之-—07 集成JIRA

    一.Jenkins Jira插件安装&配置 1. 安装插件,主要安装如下插件: Jira Issue Updater 该插件用于更新JIRA ISSUES 的工作流状态或增加备注 JIRA p ...

  2. c/c++中static和extern使用

    c/c++中static和extern使用 在C/C++中static和extern都能够用来修饰函数和变量,可是是有差别的. 内部函数和内部变量:仅仅能在文件内使用的函数和变量. 外部函数和外部变量 ...

  3. Objective C运行时(runtime)技术总结,好强大的runtime

    前言:          Objective C的runtime技术功能非常强大,能够在运行时获取并修改类的各种信息,包括获取方法列表.属性列表.变量列表,修改方法.属性,增加方法,属性等等,本文对相 ...

  4. 解决编译twrp3.0.3遇到的问题

    1. 问题: ninja: error: '/home/jessie/OMNI/out/target/product/m1/obj/SHARED_LIBRARIES/libcryptfs_hw_int ...

  5. Express:模板引擎深入研究

    深入源码 首先,看下express模板默认配置. view:模板引擎模块,对应 require('./view'),结合 res.render(name) 更好了解些.下面会看下 view 模块. v ...

  6. Mac 下如何安装pip 和xlwt

    sudo easy_install pip pip install xlwt sudo pip install xlwt sudo pip install requests

  7. Deep Learning 36:python中的一些函数

    1.map(function, sequence[, sequence, ...])函数:返回一个list作用:map的作用是以参数序列中的每一个元素调用function函数,返回包含每次functi ...

  8. 用WaveX实现音频文件的录音

    原文地址:https://blog.csdn.net/gongluck93/article/details/53096013 1.WaveInOpen waveInOpen MMRESULT wave ...

  9. ActiveMQ 安全认证

    修改配置文件 位置: apache-activemq-5.9.0/conf/ vi activemq.xml 在<broker xmlns="http://activemq.apach ...

  10. VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3

    C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input ...