![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论:最短路
文章平均质量分 62
skajre
这个作者很懒,什么都没留下…
展开
-
POJ 3114 Countries in War(强连通分量 最短路)
// // main.cpp // Richard // // Created by 邵金杰 on 16/8/18. // Copyright © 2016年 邵金杰. All rights reserved. // #include #include #include #include #include #include using namespace std; const int原创 2016-08-19 17:27:36 · 261 阅读 · 0 评论 -
POJ 3169 Layout(差分约束系统+BellmanFord)
没看题目,一直以为这题没负环,TLE了好久。 #include #include #include #include #include #include using namespace std; const int maxn=1000+5; const int inf=100000000; struct edge{ int from,to,dist; }; struct Bellman原创 2016-11-26 08:57:27 · 213 阅读 · 0 评论 -
POJ 1761 Integer Intervals(差分约束系统+BellmanFord)
#include #include #include #include #include #include using namespace std; const int maxn=10000+5; const int inf=100000000; struct edge{ int from,to,dist; }; struct BellmanFord{ int n,m; v原创 2016-11-26 08:02:03 · 197 阅读 · 0 评论 -
POJ 1364 King(差分约束系统+bellmanford)
这题主要n也取得到。 #include #include #include #include #include #include using namespace std; const int maxn=100+10; struct edge{ int from,to,dist; }; struct BellmanFord{ int n,m; vector edges;原创 2016-11-25 21:26:30 · 192 阅读 · 0 评论 -
POJ 3159 Candies(差分约束+dijkstra)
根据B-A#include #include #include #include #include #include using namespace std; const int maxn=30000+5; const int maxc=150000+5; const int inf=100000000; struct HeapNode{ int d,u; bool operato原创 2016-11-20 09:15:48 · 222 阅读 · 0 评论 -
HDU 1529 Cashier Employment(差分约束系统)
论文里已经写的很清楚了。#include #include #include #include using namespace std; const int maxn=26; const int maxc=1000+5; const int inf=100000000; struct edge{ int u,v,dist; }edges[maxc]; int cnt; int r[maxc原创 2016-11-19 21:51:29 · 183 阅读 · 0 评论 -
HDU 1384 Intervals(差分约束系统)
f[b]-f[a-1]>=c => f[b]>=f[a-1]+c a-1连边到b然后求最长路,然后再连边i-1到i为0,i到i-1为-1,跑最长路即可。#include #include #include #include #include #include using namespace std; const int maxn=50000+5; const int inf=100000000;原创 2016-11-19 17:05:15 · 206 阅读 · 0 评论 -
UVA 11478 Halum(Bellman-Ford+差分约束系统)
白书题解写的很清楚了。#include #include #include #include #include using namespace std; const int maxn=500+5; const int maxc=2700+5; struct edge{ int to,dist; }; struct BellmanFord{ int n,m; edge edg原创 2016-11-19 10:06:50 · 233 阅读 · 0 评论 -
UVA 10816 Traverl in Desert(最短路+二分)
这题精度卡了三天。#include #include #include #include using namespace std; const int maxn=211; const int maxm=21111; const double inf=(1e100); const double eps=1e-8; int n,m,s,t; struct HeapNode{ doubl原创 2017-01-14 10:45:45 · 376 阅读 · 0 评论 -
POJ 2983 Is the Information Reliable?(差分约束系统+BellmanFord)
=号转化为>=,#include #include #include #include #include #include using namespace std; const int maxn=1000+5; struct edge{ int from,to,dist; }; struct BellmanFord{ int n,m; vector edges; v原创 2016-11-26 12:47:33 · 218 阅读 · 0 评论 -
HDU 1535 Invitation Cards(BellmanFord)
#include #include #include #include #include #include using namespace std; const int maxn=1000000+5; const int inf=100000000; typedef long long LL; struct edge{ int from,to,dist; }; struct Bellman原创 2016-11-19 14:48:49 · 151 阅读 · 0 评论 -
HDU 1535 Invitation Cards(dijkstra)
#include #include #include #include #include #include using namespace std; const int maxn=1000000+5; const int inf=100000000; typedef long long LL; struct HeapNode{ LL d; int u; bool opera原创 2016-11-19 14:27:03 · 230 阅读 · 0 评论 -
POJ 3159 Candies
一道求最短路的题,时间卡得很紧,需要用优先队列(堆)来优化。 // // main.cpp // Richard // // Created by 邵金杰 on 16/8/13. // Copyright © 2016年 邵金杰. All rights reserved. // #include #include #include #include using namespace原创 2016-08-13 11:05:40 · 257 阅读 · 0 评论 -
图论 最短路径Floyd算法
#include #include using namespace std; #define MAX 100 #define INF 10000 typedef int ELemtype; typedef struct{ ELemtype arc[MAX][MAX]; int vex,edge; }AdjMatrix; void intial(AdjMatrix *G) {原创 2016-05-12 18:39:43 · 262 阅读 · 0 评论 -
图论 最短路径dijkstra算法
#include #include using namespace std; #define MAX 100 #define INFINITY 10000 typedef struct{ int arc[MAX][MAX]; int vex,edge; }AdjMatrix; void Dijkstra(AdjMatrix *G,int v0,int d[MAX]) { i原创 2016-05-12 18:23:04 · 351 阅读 · 0 评论 -
POJ 3259 Wormholes(Bellman-Ford判断是否有负权边)
// // main.cpp // Richard // // Created by 邵金杰 on 16/8/12. // Copyright © 2016年 邵金杰. All rights reserved. // #include #include using namespace std; #define INF 1<<30 struct edges{ int s,e,w原创 2016-08-13 17:42:19 · 245 阅读 · 0 评论 -
UVA 11374 Airport Express(dijkstra+枚举)
一开始想的是加一个flip标记,每条路只能由一个flip标记,但是最后发现这个标记对于记录最短时间的d数组是没有影响的。原创 2016-11-17 15:06:41 · 173 阅读 · 0 评论 -
UVA 10917 Walk Through the Forest (dijkstra+记忆化搜索)
水题1A。 #include #include #include #include #include #include using namespace std; const int maxn=1000+5; const int inf=100000000; struct HeapNode{ int d,u; bool operator < (const HeapNode &rhs原创 2016-11-17 20:30:57 · 185 阅读 · 0 评论 -
UVA 1416 Warare And Logistics(dijkstra)
思路是先暴力算出每个点的出发的最短路,然后记录下最短路树的边,枚举边,如果是最短路树上的边,那么可以删除,此时再做了一次djikstra。 自己想的时候非常贴合这个思路了,感觉只能暴力了,但是感觉这样做时间复杂度太高,最后算了下时间复杂度O(n^2mlogn),大概是刚好1e8,刚好卡着时间范围= = 。 以后想到思路还是仔细算一下复杂度,然后再决定写不写,好多次感觉时间爆了不敢写。原创 2016-11-17 21:50:00 · 197 阅读 · 0 评论 -
UVA 11090 Going in Cycle!(BellmanFord+二分)
自己想的时候只想到强连通缩点的做法,联系不到bellmanford,看了白书之后发现这方法好巧妙。#include #include #include #include #include #include using namespace std; const int maxn=50+5; struct edge{ int from,to; double dist; }; struc原创 2016-11-19 08:35:53 · 265 阅读 · 0 评论 -
UVA 10537 The Toll! Revisited(dijkstra输出字典序最小的路径)
这题就是SB题,思路很好想,但输出字典序最小的路径卡住了,一直跑不出来,最后看了别人的代码,瞬间觉得自己的代码好挫,就把别人的代码码了出来,当作最短路输出路径的模版了。#include #include #include #include #include #include #include using namespace std; typedef long long LL; const int原创 2016-11-18 21:11:14 · 405 阅读 · 0 评论