当前位置:网站首页>【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
2022-07-01 04:47:00 【AC_Dragon】
题目链接:P1629 邮递员送信 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
有一个邮递员要送东西,邮局在节点 1。他总共要送 n-1 样东西,其目的地分别是节点 2 到节点 n。由于这个城市的交通比较繁忙,因此所有的道路都是单行的,共有 m 条道路。这个邮递员每次只能带一样东西,并且运送每件物品过后必须返回邮局。求送完这 n-1 样东西并且最终回到邮局最少需要的时间。
输入格式
第一行包括两个整数,n 和 m,表示城市的节点数量和道路数量。
第二行到第 (m+1) 行,每行三个整数,u,v,w,表示从 u 到 v 有一条通过时间为 w 的道路。
输出格式
输出仅一行,包含一个整数,为最少需要的时间。
样例 #1
样例输入 #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% 的数据,1<= n <= 200。
对于 100% 的数据,1<= n <= 10^3,1 <= m <= 10^5,1<= u,v <= n,1 <= w <= 10^4,输入保证任意两点都能互相到达。
AC code:(需要快读+O2优化)
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1e3 + 10;
ll e[N][N];
const int INF = 1e8 - 1;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll n,m;
cin>>n>>m;
for(ll i=1;i<=n;i++)
for(ll j=1;j<=n;j++)
e[i][j] = INF; // 初始化各顶点之间距离均为正无穷
while(m--)
{
ll u,v,w;
cin>>u>>v>>w;
e[u][v]=min(e[u][v],w); // 可能会有重复边,保存最小权值。
}
// Floyd 算法核心语句
for(ll k=1;k<=n;k++)
for(ll i=1;i<=n;i++)
for(ll j=1;j<=n;j++)
if(e[i][k]+e[k][j]<e[i][j] && e[i][k]<INF && e[k][j]<INF)
e[i][j]=e[i][k]+e[k][j];
ll time = 0;
for(ll j=2;j<=n;j++)
time=time+e[1][j]+e[j][1];
cout<<time<<endl;
return 0;
}边栏推荐
- LeetCode_ 58 (length of last word)
- 2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- The longest increasing subsequence and its optimal solution, total animal weight problem
- Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
- Pytest automated testing - compare robotframework framework
- C -- array
- 2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
- STM32扩展版 按键扫描
- I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
猜你喜欢

解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key

Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

STM32 extended key scan

Difficulties in the development of knowledge map & the importance of building industry knowledge map

Software testing needs more and more talents. Why do you still not want to take this path?

神经网络-最大池化的使用

RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead

Cmake selecting compilers and setting compiler options
随机推荐
神经网络-最大池化的使用
Simple implementation of slf4j
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
线程安全问题
Codeworks round 449 (Div. 1) C. Kodori tree template
[2020 overview] overview of link prediction based on knowledge map embedding
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
Leecode record 1351 negative numbers in statistical ordered matrix
Cmake selecting compilers and setting compiler options
Difficulties in the development of knowledge map & the importance of building industry knowledge map
扩展-Fragment
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
Pytorch convolution operation
Dede collection plug-in does not need to write rules
LeetCode_28(实现 strStr())
Applications and features of VR online exhibition
Common methods in transforms
STM32扩展板 数码管显示
One click shell to automatically deploy any version of redis
STM32扩展版 按键扫描