
最短路
taozifish
http://www.daimayu.com/
展开
-
hdu 1385 Minimum Transport Cost
//带边权与点权的最短路,Floyd //注意查询时两点可能是同一点 #include #include #include #include using namespace std; const int INF=0xfffffff; int n, a[1005][1005], next[1005][1005], c[1005]; void init(){ int原创 2012-03-06 21:32:43 · 347 阅读 · 0 评论 -
poj 1511 Invitation Cards 静态邻接表的SPFA
//用vector写邻接表无情的TLE,只好用静态邻接表,两次SPFA分别求去和回的最短路 #include #include #include #include #include using namespace std; const int INF=0x3f3f3f3f; const int maxn=1000005; int n, m, d[maxn], pre[2][max原创 2012-03-10 21:40:19 · 411 阅读 · 0 评论 -
poj 3259 Wormholes SPFA // Bellman-ford
//最水的模版题,记下来以后忘了可以看看。 //SPFA #include #include #include #include using namespace std; const int INF=0x3f3f3f3f; const int maxn=505; int n, m, w, d[maxn], inqueue[maxn], cnt[maxn]; struct nod原创 2012-03-10 09:33:54 · 398 阅读 · 0 评论 -
poj 1724 ROADS 加限制的最短路
//SPFA+二维数组记录状态 #include #include #include #include #include using namespace std; const int INF=0x3f3f3f3f; const int maxn=10005; int n, m, d[105][maxn], pre[maxn], inqueue[maxn], cnt, money,原创 2012-03-10 22:39:36 · 419 阅读 · 0 评论 -
poj 3037 Skiing
//每个点的速度固定,与路径无关,SPFA #include #include #include #include #include using namespace std; const double inf=1e200; const int maxn=10005; double p2[105]; int h[105][105], n, pre[maxn], inqueue[m原创 2012-03-11 16:19:24 · 378 阅读 · 0 评论 -
poj 1364 King 差分约束
//注意差分约束只能求>=或 //对于差分不等式,a - b = c ,建一条 b 到 a 的权值为 c 的边,求的是最长路,得到的是最小值。存在负环的话是无解,求不出最短路(dist[ ]没有得到更新)的话是任意解。 //建图中有时候会用到一个虚点,这个点到图中每个实点的距离(dist[ ])为0,当然这个点的作用是方便图中的点入队(spfa算法),然后使这些实点的dist[ ]值得到更新。原创 2012-04-04 21:40:06 · 330 阅读 · 0 评论 -
poj 2607 Fire Station
枚举点求单源最短路 Memory: 748K Time: 204MS Language: G++ Result: Accepted #include #include #include #include #include #include using namespace std; const int maxn=505; const原创 2012-04-29 11:45:11 · 481 阅读 · 0 评论 -
poj 1556 The Doors
计算几何+最短路 通过线段是否完全相交判断两点的连通性。 #include #include #include #include using namespace std; const double inf=1e10; const double EP=1e-8; struct Point{ double x, y; }p[105]; //4*n+2 stru原创 2012-09-06 15:26:49 · 419 阅读 · 0 评论