当前位置:网站首页>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;
}
边栏推荐
- Is the controller a single instance or multiple instances? How to ensure the safety of concurrency
- How about opening an account at Hengtai securities? Is it safe?
- Double efficiency. Six easy-to-use pychar plug-ins are recommended
- "Learning notes" recursive & recursive
- Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
- Hcip day 15 notes
- 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?
- Gossip about redis source code 76
- 股票开户佣金最低的券商有哪些大家推荐一下,手机上开户安全吗
- D26: the nearest number (translation + solution)
猜你喜欢
[note] IPC traditional interprocess communication and binder interprocess communication principle
Enter MySQL in docker container by command under Linux
Apple released a supplementary update to MacOS Catalina 10.15.5, which mainly fixes security vulnerabilities
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
How will the complete NFT platform work in 2022? How about its core functions and online time?
Solve the problem that the kaggle account registration does not display the verification code
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Tencent interview: can you find the number of 1 in binary?
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
随机推荐
Pyqt5 sensitive word detection tool production, operator's Gospel
在恒泰证券开户怎么样?安全吗?
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Scratch uses runner Py run or debug crawler
Introducing Software Testing
Gorilla/mux framework (RK boot): add tracing Middleware
C # basic knowledge (3)
What is the difference between NFT, SFT and dnft? How to build NFT platform applications?
C # basic knowledge (1)
D25:sequence search (sequence search, translation + problem solving)
What is the Valentine's Day gift given by the operator to the product?
ADB related commands
2/14 (regular expression, sed streaming editor)
Unsafe and CAS principle
D23:multiple of 3 or 5 (multiple of 3 or 5, translation + solution)
股票开户最低佣金炒股开户免费,网上开户安全吗
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Fluent learning (5) GridView
QT creator source code learning note 05, how does the menu bar realize plug-in?
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination