有n个节点的m条无向边的图,节点编号为1~n 然后有点权和边权,给出q个询问,每一个询问给出2点u,v 输出u,v的最短距离 这里的最短距离规定为: u到v的路径的所有边权+u到v路径上最大的一个点权的和(点权也可以是u,v) n<=1000 m<=20000 Q<=20000 时限:5000ms 没有点权的话,好处理 加了点权呢? 我们可以先枚举n个节点,跑n次spfa,当枚举节点u时,我们默认节点u是所有路径上点权最大的一个点 即我们枚举节点u时,我们先把点权比u大的节点删除了,在剩…
Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:10005   Accepted: 3523 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. O…
Cycling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1247    Accepted Submission(s): 411 Problem Description You want to cycle to a programming contest. The shortest route to the contest migh…
Sightseeing Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 404664-bit integer IO format: %lld      Java class name: Main   CC and MM arrive at a beautiful city for sightseeing. They have found a map of the c…
题目 Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. On this way, the tourists in the bus can see the sights alongside the route travelled. Moreover, the bus…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Invitation Cards Time Limit: 5 Seconds      Memory Limit: 65536 KB In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fa…
POJ 1637 Sightseeing tour 题目链接 题意:给一些有向边一些无向边,问能否把无向边定向之后确定一个欧拉回路 思路:这题的模型很的巧妙,转一个http://blog.csdn.net/pi9nc/article/details/12223693 先把有向边随意定向了,然后依据每一个点的入度出度之差,能够确定每一个点须要调整的次数,然后中间就是须要调整的边,容量为1,这样去建图最后推断从源点出发的边是否都满流就可以 代码: #include <cstdio> #includ…
Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10306   Accepted: 3519 Description Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to…
The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1744 Description Once upon a time, in a faraway land, there lived a king. This king owned a small collection of rare and valuable trees, which had been…
Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3361    Accepted Submission(s): 1073 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo…
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: 说实话,上次写类似的二维状态最短路Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra],我没能把手写二叉堆优化Dijkstra的给写出来. 这次费了点功夫,也算是给写出来了,需要注意的点还是有点多的.而且我终于深刻理解为啥不推荐手写二叉堆了,主要是代码量相比…
title: hdu-3790最短路刷题 date: 2018-10-20 14:50:31 tags: acm 刷题 categories: ACM-最短路 概述 一道最短路的水题,,,尽量不看以前的代码打出来,,,熟悉一下dijkstra的格式和链式前向星的写法,,,, 虽然是水题,,,但是一开始没考虑取费用最短的wa了一发,,,,QAQ 分析 链式前向星存图,,再加一个数组保存源点到每个点的费用cst[maxm],,,注意取最少的费用 代码 #include <iostream> #in…
解题关键:k短路模板题,A*算法解决. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> #include<queue> using namespace std; typedef long long ll; ; ; const int inf=1e9; str…
http://poj.org/problem?id=1061 傻逼题不多说 (x+km) - (y+kn) = dL 求k 令b = n-m ; a = x - y ; 化成模线性方程一般式 : Lx+by=a 再除gcd化简成最简形式 使得L,b互素 (即构造 L'x+b'y =1) 求Ex_GCD得到 y * a 就是最后的答案...还是一样要化成正整数形式 pair<LL,LL> ex_gcd(LL a,LL b){ ) ,); pair<LL,LL> t = ex_gcd(…
链接:https://www.nowcoder.com/acm/contest/136/I来源:牛客网 题目描述 P市有n个公交站,之间连接着m条道路.P市计划新开设一条公交线路,该线路从城市的东站(s点)修建到西站(t点),请为P市设计一条满足上述条件并且最短的公交线路图. 输入描述: 第一行有5个正整数n,m,s,t. 接下来m行,每行3个数a,b,v描述一条无向道路a——b,长度为v. 输出描述: 如果有解,输出一行,表示满足条件的最短公交线路的长度c. 否则,输出“-1” 输入例子: 3…
http://poj.org/problem?id=3463 Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 2270 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from…
F - Sightseeing 传送门: POJ - 3463 分析 一句话题意:给你一个有向图,可能有重边,让你求从s到t最短路的条数,如果次短路的长度比最短路的长度多1,那么在加上次短路的条数. 这道题唯一要注意的就是次短路的求法 首先题目中说从起点到终点至少有一条路径,所以我们就不用考虑不可达的情况 我们先考虑如果a到b有一条边,b到c有一条边 那么a到c经过b的路程中次短路只有两种选择,一种是a到b的最短路+b到c的次短路,另一种是a到b的次短路+b到c的次短路 所以我们只需要记录次短路…
1.poj  1847  Tram   最短路 2.总结:用dijkstra做的,算出a到其它各个点要改向的次数.其它应该也可以. 题意: 有点难懂.n个结点,每个点可通向ki个相邻点,默认指向第一个相邻点,可以改变指向.求一条从A到B的路,使用最少改变路上点的指向的次数. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm>…
题目链接:http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. &quo…
题目:http://poj.org/problem?id=3463 当然要给一个点记最短路和次短路的长度和方案. 但往优先队列里放的结构体和vis竟然也要区分0/1,就像把一个点拆成两个点了一样. 不要区分k的fx. #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; ,M=; ],f[N][],st,en; ]; struct…
传送门:http://poj.org/problem?id=1815 题意:给N个点,已知S与T,和邻接矩阵,求拆掉那些点会减小最大流. 思路:点之间有线连接的在网络中的权值为inf,没有的就不用管,将除S与T外的每个点(题意说了不能拆这两个)变成一个入点->出点且权值为1,也就是拆点,然后跑网络流可以得到第一问解.再进行枚举,在网络中依次删去点,比较得出的最大流是否跟未删点的网络流一样,if一样说明不需要删,else则说明需要,输出即可.   https://blog.csdn.net/Vmu…
Dijkstra模板题,也可以用Floyd算法. 关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的. 写法1: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define Mod 1000000007 using namespace std; #define N 1007 int mp…
/* 对dij的再一次理解 每个点依旧永久标记 只不过这里多搞一维 0 1 表示最短路还是次短路 然后更新次数相当于原来的两倍 更新的时候搞一下就好了 */ #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<vector> #define maxn 1010 using namespace std; ],f[maxn][],c[maxn][…
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessa…
昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 51879   Accepted: 15584 Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低要求.酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币.如果你能够弄来他的水晶球,那么只要5000…
Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the…
题意:求两点之间最短路的数目加上比最短路长度大1的路径数目 分析:可以转化为求最短路和次短路的问题,如果次短路比最短路大1,那么结果就是最短路数目加上次短路数目,否则就不加. 求解次短路的过程也是基于Dijkstra的思想.算法中用一个二维数组d[u][tag](tag=0代表最短路,1代表次短路)来记录最短路和次短路的长度,cnt[u][tag]记录二者的数目.所以每个点都有两个访问状态,一个是最短路已经确定,另一个是次短路已经确定,所以vis[u][tag]数组也是二维的. 每次维护邻接点的…
畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 55641    Accepted Submission(s): 20842 Problem Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走…
嗯,这是我上一篇文章说的那本宝典的第二题,我只想说,真TM是本宝典……做的我又痛苦又激动……(我感觉ACM的日常尽在这张表情中了) 题目链接:http://poj.org/problem?id=1637 Time Limit: 1000MS Memory Limit: 10000K Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that t…
Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6986   Accepted: 2901 Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beauti…