当前位置:网站首页>P1339 [USACO09OCT]Heat Wave G
P1339 [USACO09OCT]Heat Wave G
2022-07-03 23:46:00 【Statichit static smash】
Title Description
There is one n A little bit m Undirected graph of strip and edge , Request from s To t The shortest path length of .
Input format
First line four positive integers n,m,s,t. Next mm That's ok , Three positive integers per line u,v,w, Indicates a connection u,v, Long for w The edge of .
Output format
Output a line of integers , Answer .
I/o sample
Input #1 Copy
7 11 5 4 2 4 2 1 4 3 7 2 2 3 4 3 5 7 5 7 3 3 6 1 1 6 3 4 2 4 3 5 6 3 7 2 1Output #1 Copy
7explain / Tips
【 Data range 】
about 100\%100% The data of ,1\le n \le 25001≤n≤2500,1\le m \le 62001≤m≤6200,1\le w \le 10001≤w≤1000.【 Sample explanation 】
5 \to 6 \to 1 \to 45→6→1→4 It's the shortest path , The length is 3+1+3 = 73+1+3=7.
The most basic dijastra template can be solved
ac Code
#include<bits/stdc++.h>
using namespace std;
#define inf 99999999
int n,m,s,t;
int a,b,l;
int v[2600][2600];
int dis[2600];
int book[2600];// Initializes the default as 0
int main()
{
cin>>n>>m>>s>>t;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
if(i == j)v[i][j]=0;
else v[i][j]=inf;
}
while(m--)
{
cin>>a>>b>>l;
v[a][b]=l;
v[b][a]=l;
}
for(int i=1;i<=n;i++)
dis[i]=v[s][i];
book[s]=1;
for(int i=1;i<=n-1;i++)
{
int _min=inf,u;
for(int j=1;j<=n;j++)// Find the point closest to the vertex
{
if(book[j] == 0 && dis[j] < _min)
{
_min=dis[j];
u=j;// And record its coordinates
}
}
book[u]=1;
for(int j=0;j<=n;j++)
dis[j]=min(dis[j],dis[u]+v[u][j]);// Compare s Point to j The distance and s Point to u Again from u To j Distance of , If the distance becomes shorter, replace
}
cout<<dis[t];
return 0;
}
边栏推荐
- 2/14 (regular expression, sed streaming editor)
- Analysis of refrigeration and air conditioning equipment operation in 2022 and examination question bank of refrigeration and air conditioning equipment operation
- D30:color tunnels (color tunnels, translation)
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- How about opening an account at Hengtai securities? Is it safe?
- Gossip about redis source code 73
- D23:multiple of 3 or 5 (multiple of 3 or 5, translation + solution)
- How to understand the gain bandwidth product operational amplifier gain
- FPGA tutorial and Allegro tutorial - link
- Selenium library 4.5.0 keyword explanation (I)
猜你喜欢

leetcode-43. String multiplication

Investment demand and income forecast report of China's building ceramics industry, 2022-2028

2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) simulated examination and Guangdong Provincial Safety Officer a certificate third batch (main person in charg

How to write a good title of 10w+?

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

Solve the problem that the kaggle account registration does not display the verification code

Correlation analysis summary

Hcip 13th day notes

The interviewer's biggest lie to deceive you, bypassing three years of less struggle

Fluent learning (5) GridView
随机推荐
China standard gas market prospect investment and development feasibility study report 2022-2028
Version rollback revert don't reset better reset must be forced
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?
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
Cgb2201 preparatory class evening self-study and lecture content
Research Report on the scale prediction of China's municipal engineering industry and the prospect of the 14th five year plan 2022-2028
Selenium check box
Idea set class header comments
"Learning notes" recursive & recursive
Design of logic level conversion in high speed circuit
How to prevent malicious crawling of information by one-to-one live broadcast source server
ADB related commands
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Investment demand and income forecast report of China's building ceramics industry, 2022-2028
QT creator source code learning note 05, how does the menu bar realize plug-in?
Idea integrates Microsoft TFs plug-in
2022 a special equipment related management (elevator) examination questions and a special equipment related management (elevator) examination contents
How to make icons easily
2/14 (regular expression, sed streaming editor)
Deep learning ----- using NN, CNN, RNN neural network to realize MNIST data set processing