题目传送门:邮递员送信
题目描述
有一个邮递员要送东西,邮局在节点 1。他总共要送 n-1 样东西,其目的地分别是节点 2 到节点 n。由于这个城市的交通比较繁忙,因此所有的道路都是单行的,共有 m 条道路。这个邮递员每次只能带一样东西,并且运送每件物品过后必须返回邮局。求送完这 n−1 样东西并且最终回到邮局最少需要的时间。
输入格式
第一行包括两个整数,n 和 m,表示城市的节点数量和道路数量。
第二行到第 (m+1) 行,每行三个整数,u,v,w,表示从 u 到 v 有一条通过时间为 w 的道路。
输出格式
输出仅一行,包含一个整数,为最少需要的时间。
输入输出样例
输入 #1
5 10
2 3 5
1 5 5
3 5 6
1 2 8
1 3 8
5 3 4
4 1 8
4 5 3
3 5 6
5 4 2
输出 #1
83
说明/提示
对于 30%30% 的数据 1<=n<=200
对于 100%100% 的数据 1<=n<=1000,1<=m<=100000,1<=u,v<=n,1<=w<=10000,输入保证任意两点都能互相到达。
思路:
先求1到n-1个点的最短距离s1,然后求n-1个点到1的最短距离s2,输出s1+s2即可。
在这里 s2需要反向建边转化求1到n-1个点的最短距离。
废话少说,上代码
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<utility>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#