当前位置:网站首页>P1629 postman delivering letter
P1629 postman delivering letter
2022-07-03 23:46:00 【Statichit static smash】
Title Description
There's a postman to deliver , The post office is at the node 11. All in all, he will send n-1n−1 things , The destinations are nodes 22 To the node nn. Because of the heavy traffic in this city , So all roads are one-way , share mm 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-1n−1 Something and Finally back to the post office The least time required .
Input format
The first line contains two integers ,nn and mm, Indicates the number of nodes and roads in the city .
Line two to line two (m+1)(m+1) That's ok , Three integers per row ,u,v,wu,v,w, From uu To vv There is a passage time of ww The path of .
Output format
Output only one line , Contains an integer , For the least time needed .
I/o sample
Input #1 Copy
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 2Output #1 Copy
83explain / Tips
about 30\%30% The data of ,1 \leq n \leq 2001≤n≤200.
about 100\%100% The data of ,1 \leq n \leq 10^31≤n≤103,1 \leq m \leq 10^51≤m≤105,1\leq u,v \leq n1≤u,v≤n,1 \leq w \leq 10^41≤w≤104, Input ensures that any two points can reach each other .
// This question needs to get the shortest weight between every two points , So want to use floyd
// open o2 To live through , Otherwise t( What principle is this , Fantastic! )
Because the input data , The distance between two points may be more than one , To avoid overwriting , must do Go to the heavy side , Select the minimum distance among multiple inputs as the initial distance between the two points
Because every time the postman delivers a letter, he has to return to the post office ( Starting point ), Again because floyd Calculate the shortest path between every two points , So the final calculation result is directly in for In circulation ans+=v[1][i]+v[i][1]; that will do
ac Code ( Must open O2 Optimize )
#include<bits/stdc++.h>
using namespace std;
#define inf 999999
int n,m,v[1010][1010];
int x,y,z;
int main()
{
memset(v,inf,sizeof(v));
scanf("%d%d",&n,&m);
for(int i=1; i<=m; ++i)
{
scanf("%d%d%d",&x,&y,&z);
v[x][y]=min(z,v[x][y]);// Go to the heavy side
}
//flody
for(int k=1; k<=n; ++k)
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
v[i][j]=min(v[i][k]+v[k][j],v[i][j]);
int ans=0;
for(int i=2; i<=n; ++i)
ans+=v[1][i]+v[i][1];// Time of each visit + Time to come back
cout<<ans;
return 0;
}
边栏推荐
- Pyqt5 sensitive word detection tool production, operator's Gospel
- The difference between single power amplifier and dual power amplifier
- C # basic knowledge (3)
- NPM script
- Xiangong intelligent obtained hundreds of millions of yuan of b-round financing to accelerate the process of building non-standard solutions with standardized products
- Les sociétés de valeurs mobilières dont la Commission d'ouverture d'un compte d'actions est la plus faible ont ce que tout le monde recommande.
- Analysis of refrigeration and air conditioning equipment operation in 2022 and examination question bank of refrigeration and air conditioning equipment operation
- Qtoolbutton available signal
- Interpretation of corolla sub low configuration, three cylinder power configuration, CVT fuel saving and smooth, safety configuration is in place
- Gossip about redis source code 80
猜你喜欢

SPI based on firmware library

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Pytorch learning notes 5: model creation

Report on the construction and development mode and investment mode of sponge cities in China 2022-2028

Smart fan system based on stm32f407

Introducing Software Testing

Scratch uses runner Py run or debug crawler

Exclusive download! Alibaba cloud native brings 10 + technical experts to bring "new possibilities of cloud native and cloud future"

JDBC Technology

Sort merge sort
随机推荐
股票開戶傭金最低的券商有哪些大家推薦一下,手機上開戶安全嗎
2022 free examination questions for hoisting machinery command and hoisting machinery command theory examination
Make small tip
Selenium check box
D26: the nearest number (translation + solution)
Exclusive download! Alibaba cloud native brings 10 + technical experts to bring "new possibilities of cloud native and cloud future"
Hcip day 15 notes
I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
Scratch uses runner Py run or debug crawler
Gossip about redis source code 75
Briefly understand the operation mode of developing NFT platform
D25:sequence search (sequence search, translation + problem solving)
Pyqt5 sensitive word detection tool production, operator's Gospel
Introducing Software Testing
Pandaoxi's video
Idea set class header comments
D24:divisor and multiple (divisor and multiple, translation + solution)
Day30-t540-2022-02-14-don't answer by yourself
"Learning notes" recursive & recursive
"Learning notes" recursive & recursive