http://poj.org/problem?id=3463 Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7252   Accepted: 2581 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from…
Bellman-ford 算法适用于含有负权边的最短路求解,复杂度是O( VE ),其原理是依次对每条边进行松弛操作,重复这个操作E-1次后则一定得到最短路,如果还能继续松弛,则有负环.这是因为最长的没有环路的路,也只不过是V个点E-1条边构成的,所以松弛E-1次一定能得到最短路.因此这个算法相比 Dijkstra 首先其是对边进行增广,其次它能检测出负环的存在(若负环存在,那么最短路是取不到的,因为可以一直绕着这个负环将最小路径值不断缩小),这个弥补了 Dijkstra 的不足,但是其算法跑的…
SPFA(Shortest Path Faster Algorithm)算法,是一种求最短路的算法. SPFA的思路及写法和BFS有相同的地方,我就举一道例题(洛谷--P3371 [模板]单源最短路径(弱化版)来做讲解吧! 如题: 首先,我们先来定义一波变量吧: struct node{ int v,w; node (){ } node (int _v,int _w){ v=_v; w=_w; }//构造函数 }; queue<int>qu;//必备队列 const int inf=0x3f3…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1688 题意:第k短路,这里要求的是第1短路(即最短路),第2短路(即次短路),以及路径条数,最后如果最短路和次短路长度差1,则输出两种路径条数之和,否则只输出最短路条数. 思路:dijkstra变形,注意状态的转移,代码上附了注释,就不多说了.. 代码: #include <bits/stdc++.h> #define MAXN 1010 using namespace std; vector&l…
Sightseeing Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1023    Accepted Submission(s): 444 Problem Description Tour operator Your Personal Holiday organises guided bus trips across the Ben…
Marriage Match IV 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/Q Description Do not sincere non-interference. Like that show, now starvae also take part in a show, but it take place between city A and B. Starvae is in city A and girls a…
http://www.cnblogs.com/wally/archive/2013/04/16/3024490.html http://blog.csdn.net/me4546/article/details/6584448 维护最短路长度d[i][0]和次短路d[i][1],最短路条数dp[i][0]和次短路dp[i][1] #include <iostream> #include <string> #include <cstring> #include <cs…
Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9247   Accepted: 3242 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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3191 How Many Paths Are There Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2128    Accepted Submission(s): 749 Problem Description   oooccc1 is…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1688 题目大意:给n个点,m条有向边.再给出起点s, 终点t.求出s到t的最短路条数+次短路条数. 思路: 1.最短路和次短路是紧密相连的,在最短路松弛操作中,当我们找到一条更短的路径,也就意味着之前的路径不再是最短路,而成为了次短路,利用这个关系可以实现状态的转移. 2.好久没写优先队列了,都忘记了加个 priority_queue, 这样才能写重载,才能排序. 注释在代码里: #include<…