专题四 最短路
Dijkstra floyd SPFA
Lewisprince
这个作者很懒,什么都没留下…
展开
-
POJ1847 Tram Priority-Queue优化dij
Sample Input 3 2 1 2 2 3 2 3 1 2 1 2 Sample Output 0 注意使用priority queue优化时判断continue的位置,同时注意cmp重载的写法 #include <iostream> #include <vector> #include <queue> using namespace std; struct edge{ int end; int cost; edge(int m,int n) { e.原创 2020-06-17 16:53:43 · 112 阅读 · 0 评论 -
POJ3268 Silver Cow Party 反向建图(Dijkstra)
Sample Input 4 8 2 1 2 4 1 3 2 1 4 7 2 1 1 2 3 5 3 1 2 3 4 4 4 2 3 Sample Output 10 注意: 在写正向和反向dij的时候注意替换全部的dis和visited为另外一个数组 否则你就会debug两小时(逃) 考虑提前终止条件,当前点的更新最好放在循环外边 考虑用邻接数组代替邻接链表?(节省时间) 代码如下: #include <stdio.h> #include <iostream> #inclu.原创 2020-06-13 18:12:10 · 142 阅读 · 0 评论 -
POJ2387 Til the Cows Come Home Dij模板题(Dijkstra)
直接建图dij遍历就行 注意测试数据路径cost不是在100以内的 无穷值需要设的大一些 (inf = pow(x,y)在代码提交后会编译错误…用10000007代替了) Sample Input 5 5 1 2 20 2 3 30 3 4 20 4 5 20 1 5 100 Sample Output 90 代码 #include <stdio.h> #include <cmath> #include <iostream> #include <vector&.原创 2020-06-10 21:32:02 · 138 阅读 · 0 评论