当前位置:网站首页>[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;
}边栏推荐
猜你喜欢

2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination

Extension fragment

【硬十宝典】——1.【基础知识】电源的分类

分布式全局唯一ID解决方案详解

Data loading and preprocessing

2022 hoisting machinery command registration examination and hoisting machinery command examination registration

C -- array

Use and modification of prior network model

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点

CF1638E. Colorful operations Kodori tree + differential tree array
随机推荐
缓冲流与转换流
先有网络模型的使用及修改
STM32扩展板 数码管显示
The longest increasing subsequence and its optimal solution, total animal weight problem
【暑期每日一题】洛谷 P2026 求一次函数解析式
分布式锁的实现
Pytorch(一) —— 基本语法
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
神经网络-最大池化的使用
CF1638E. Colorful operations Kodori tree + differential tree array
LeetCode_35(搜索插入位置)
神经网络-非线性激活
分布式事务-解决方案
How to do the performance pressure test of "Health Code"
Basic skeleton of neural network nn Use of moudle
Common UNIX Operation and maintenance commands of shell
Pytoch (I) -- basic grammar
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
[hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
Dual contractual learning: text classification via label aware data augmentation reading notes