当前位置:网站首页>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;
}
边栏推荐
- Gossip about redis source code 80
- Selenium library 4.5.0 keyword explanation (III)
- Common mode interference of EMC
- Analysis on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition
- Make small tip
- How will the complete NFT platform work in 2022? How about its core functions and online time?
- Idea integrates Microsoft TFs plug-in
- C # basic knowledge (1)
- Bufferpool caching mechanism for executing SQL in MySQL
- Current detection circuit - including op amp current scheme
猜你喜欢

Briefly understand the operation mode of developing NFT platform

Gorilla/mux framework (RK boot): add tracing Middleware

Tencent interview: can you pour water?

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
![[source code] VB6 chat robot](/img/89/46b67f627c8257eaddc70a247c9ba5.jpg)
[source code] VB6 chat robot
![[Happy Valentine's day]](/img/d9/9280398eb64907a567df6eea772adb.jpg)
[Happy Valentine's day] "I still like you very much, like sin ² a+cos ² A consistent "(white code in the attached table)

Pyqt5 sensitive word detection tool production, operator's Gospel

Alibaba cloud container service differentiation SLO hybrid technology practice

Kubedl hostnetwork: accelerating the efficiency of distributed training communication

Cgb2201 preparatory class evening self-study and lecture content
随机推荐
Interesting 10 CMD commands
[note] IPC traditional interprocess communication and binder interprocess communication principle
[issue 16] golang's one-year experience in developing Purdue Technology
Comment obtenir une commission préférentielle pour l'ouverture d'un compte en bourse? Est - ce que l'ouverture d'un compte en ligne est sécurisée?
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
炒股開戶傭金優惠怎麼才能獲得,網上開戶安全嗎
Sword finger offer day 4 (Sword finger offer 03. duplicate numbers in the array, sword finger offer 53 - I. find the number I in the sorted array, and the missing numbers in sword finger offer 53 - ii
Esp-idf turns off serial port log output.
[MySQL] sql99 syntax to realize multi table query
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
leetcode-43. String multiplication
Minimum commission for stock account opening. Stock account opening is free. Is online account opening safe
Actual combat | use composite material 3 in application
Gossip about redis source code 75
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 on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition
Pyqt5 sensitive word detection tool production, operator's Gospel
C # basic knowledge (1)
Selenium library 4.5.0 keyword explanation (II)
2022 examination of safety production management personnel of hazardous chemical production units and examination skills of safety production management personnel of hazardous chemical production unit