
最短路径
ln2037
用心雕琢我的艺术品。
展开
-
P1522 [USACO2.4]牛的旅行 Cow Tours 【Floyd】
题目描述Farmer John 的农场里有很多牧区。有的路径连接一些特定的牧区。一片所有连通的牧区称为一个牧场。但是就目前而言,你能看到至少有两个牧区通过任何路径都不连通。这样,Farmer John 就有多个牧场了。John 想在牧场里添加恰好一条路径。对这条路径有以下限制:一个牧场的直径就是牧场中最远的两个牧区的距离(本题中所提到的所有距离指的都是最短的距离)。考虑如下的有5个牧区的牧场,牧区用 * 表示,路径用直线表示。每一个牧区都有自己的坐标: (15,15) (20,原创 2020-10-07 21:19:41 · 283 阅读 · 0 评论 -
P1629 邮递员送信 【Dijkstra + 堆优化】
题目描述有一个邮递员要送东西,邮局在节点 111。他总共要送 n−1n-1n−1 样东西,其目的地分别是节点 222 到节点 nnn。由于这个城市的交通比较繁忙,因此所有的道路都是单行的,共有 mmm 条道路。这个邮递员每次只能带一样东西,并且运送每件物品过后必须返回邮局。求送完这 n−1n-1n−1 样东西并且最终回到邮局最少需要的时间。输入格式第一行包括两个整数,nnn 和 mmm,表示城市的节点数量和道路数量。第二行到第 (m+1)(m+1)(m+1) 行,每行三个整数,u,v,wu,v,wu原创 2020-10-07 20:15:22 · 434 阅读 · 0 评论 -
P4779 【模板】单源最短路径(标准版) 【Dijkstra + 堆优化】
#include <iostream>#include <algorithm>#include <climits>#include <cmath>#include <queue>using namespace std;const int inf = 1e9 + 100;const int maxn = 2e5 + 10;struct node{ int v; int len, nex;}edge[maxn <<原创 2020-10-07 20:14:34 · 164 阅读 · 0 评论 -
P3371 【模板】单源最短路径(弱化版)【Dijkstra】
题目背景本题测试数据为随机数据,在考试中可能会出现构造数据让SPFA不通过,如有需要请移步 P4779。题目描述如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度。输入格式第一行包含三个整数 n,m,sn,m,sn,m,s,分别表示点的个数、有向边的个数、出发点的编号。接下来 mmm 行每行包含三个整数 u,v,wu,v,wu,v,w,表示一条 u→vu \to vu→v 的,长度为 www 的边。输出格式输出一行 nnn 个整数,第 iii 个表示 sss 到第 iii 个点的原创 2020-10-07 20:13:26 · 234 阅读 · 0 评论 -
P1364 医院设置 【Floyd】
题目描述设有一棵二叉树,如图:其中,圈中的数字表示结点中居民的人口。圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接点之间的距离为 111。如上图中,若医院建在1 处,则距离和 =4+12+2×20+2×40=136=4+12+2\times20+2\times40=136=4+12+2×20+2×40=136;若医院建在 333 处,则距离和 =4×2+13+20+40=81=4\times2+13+20+40=81=4×2+13+20+40=原创 2020-10-03 18:08:20 · 500 阅读 · 0 评论 -
最短路径之Floyd
Floyd本质上就是通过前k个节点来更新i和j之间的最短路径。#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;const int maxn = 2e2 + 10;const int inf = 1...原创 2019-12-12 22:27:36 · 244 阅读 · 0 评论 -
最短路径之SPFA
#include <iostream>#include <cstring>#include <queue>#include <algorithm>#include <cstdio>using namespace std;const int maxn = 1e6 + 10;const int inf = 1e9 + 7;c...原创 2019-12-12 13:57:09 · 198 阅读 · 0 评论 -
Dijkstra的堆优化
在寻找未访问过的最小的 d[u] 时, 未优化的dijkstra算法的寻找方法是遍历d数组, 而采用堆优化的dijkstra算法是创建一个优先队列, 每次取队首元素,即所要寻找的d[u], 时间复杂度比起未优化的要强太多。#include <iostream>#include <cstring>#include <queue>#include <...原创 2019-12-12 11:48:11 · 303 阅读 · 0 评论 -
最短路径之Dijkstra
距上次敲最短路已过去将近一年了吧。如今再敲, 存图方式也从邻接矩阵, 邻接表变成了更优秀的链式向前星。时间过得真快呀。#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;const int maxn ...原创 2019-12-11 18:09:00 · 228 阅读 · 0 评论 -
Heavy Transportation POJ - 1797
Heavy Transportation POJ - 1797BackgroundHugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really ...原创 2019-03-19 11:57:21 · 168 阅读 · 0 评论 -
Til the Cows Come Home POJ - 2387
Til the Cows Come Home POJ - 2387Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her b...原创 2019-03-16 00:12:18 · 195 阅读 · 0 评论 -
Silver Cow Party POJ - 3268
Silver Cow Party POJ - 3268给出n,m,代表牛数和边数,接着是m条有向边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x,除了牛x之外的牛,他们都有一个参加聚会并且回来的最短时间,从这些最短时间里找出一个最大值输出 N<=1000,M<=100,000InputLine 1: Three spac...原创 2019-03-19 18:01:00 · 177 阅读 · 0 评论