当前位置:网站首页>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;
}
边栏推荐
- Deep learning ----- using NN, CNN, RNN neural network to realize MNIST data set processing
- Idea a method for starting multiple instances of a service
- 在恒泰证券开户怎么样?安全吗?
- Cgb2201 preparatory class evening self-study and lecture content
- Tencent interview: can you find the number of 1 in binary?
- 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
- Hcip day 15 notes
- How to quickly build high availability of service discovery
- Unity shader visualizer shader graph
- Pyqt5 sensitive word detection tool production, operator's Gospel
猜你喜欢
Idea a method for starting multiple instances of a service
2022.02.13
Solve the problem that the kaggle account registration does not display the verification code
What is the Valentine's Day gift given by the operator to the product?
Zipper table in data warehouse (compressed storage)
Bufferpool caching mechanism for executing SQL in MySQL
Gorilla/mux framework (RK boot): add tracing Middleware
The interviewer's biggest lie to deceive you, bypassing three years of less struggle
[note] IPC traditional interprocess communication and binder interprocess communication principle
Unsafe and CAS principle
随机推荐
Fluent learning (5) GridView
The difference between single power amplifier and dual power amplifier
[source code] VB6 chat robot
Interesting 10 CMD commands
Gossip about redis source code 78
Op amp related - link
Errors taken 1 Position1 argument but 2 were given in Mockingbird
How about opening an account at Hengtai securities? Is it safe?
Cgb2201 preparatory class evening self-study and lecture content
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
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 understand the gain bandwidth product operational amplifier gain
Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~
2/14 (regular expression, sed streaming editor)
Zipper table in data warehouse (compressed storage)
Fudan 961 review
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.
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
Introduction to the gtid mode of MySQL master-slave replication
C # basic knowledge (1)