当前位置:网站首页>[daily question in summer] letter delivery by p1629 postman in Luogu (to be continued...)
[daily question in summer] letter delivery by p1629 postman in Luogu (to be continued...)
2022-07-01 04:48:00 【AC_ Dragon】
Topic link :P1629 The postman delivers the mail - Luogu | New ecology of computer science education (luogu.com.cn)
Title Description
There's a postman to deliver , The post office is at the node 1. All in all, he will send n-1 things , The destinations are nodes 2 To the node n. Because of the heavy traffic in this city , So all roads are one-way , share m road . This postman can only carry one thing at a time , also After delivering each item, you must return to the post office . Please finish the delivery n-1 Something and Finally back to the post office The least time required .
Input format
The first line contains two integers ,n and m, Indicates the number of nodes and roads in the city .
Line two to line two (m+1) That's ok , Three integers per row ,u,v,w, From u To v There is a passage time of w The path of .
Output format
Output only one line , Contains an integer , For the least time needed .
Examples #1
The sample input #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 2Sample output #1
83Tips
about 30% The data of ,1<= n <= 200.
about 100% The data of ,1<= n <= 10^3,1 <= m <= 10^5,1<= u,v <= n,1 <= w <= 10^4, Input ensures that any two points can reach each other .
AC code:( Need to read fast +O2 Optimize )
#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; // Initialize that the distance between vertices is positive infinite
while(m--)
{
ll u,v,w;
cin>>u>>v>>w;
e[u][v]=min(e[u][v],w); // There may be duplicate edges , Save minimum weight .
}
// Floyd Algorithm core statement
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;
}边栏推荐
- Talk about testdeploy
- C -- array
- 常用的Transforms中的方法
- Pytest automated testing - compare robotframework framework
- 解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- Thoughts on the construction of Meizhou cell room
- How to do the performance pressure test of "Health Code"
- LeetCode_ 58 (length of last word)
猜你喜欢

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

Neural network convolution layer

The longest increasing subsequence and its optimal solution, total animal weight problem

Common methods in transforms

Cmake selecting compilers and setting compiler options

How to do the performance pressure test of "Health Code"

RuntimeError: “max_pool2d“ not implemented for ‘Long‘

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

C -- array

One click shell to automatically deploy any version of redis
随机推荐
Pytorch(二) —— 激活函数、损失函数及其梯度
Codeforces Round #771 (Div. 2) ABCD|E
缓冲流与转换流
Use of dataloader
LeetCode_ 53 (maximum subarray and)
RDF query language SPARQL
Leecode question brushing record 1310 subarray XOR query
Shell之一键自动部署Redis任意版本
线程安全问题
pytorch中常用数据集的使用方法
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
VIM easy to use tutorial
打印流与System.setout();
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
Leecode records the number of good segmentation of 1525 strings
Matters behind the construction of paint testing laboratory
常用的Transforms中的方法
Construction of Meizhou nursing laboratory: equipment configuration
Pytorch neural network construction template
神经网络-使用Sequential搭建神经网络