当前位置:网站首页>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;
}
边栏推荐
- 2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
- [issue 16] golang's one-year experience in developing Purdue Technology
- Analysis of refrigeration and air conditioning equipment operation in 2022 and examination question bank of refrigeration and air conditioning equipment operation
- D25:sequence search (sequence search, translation + problem solving)
- How to make recv have a little temper?
- Hcip day 12 notes
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- leetcode-43. String multiplication
- Fudan 961 review
- Scratch uses runner Py run or debug crawler
猜你喜欢

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

Gorilla/mux framework (RK boot): add tracing Middleware
![Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~](/img/af/1975b37d81bbdb9709ff181b9a72f9.jpg)
Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~

Actual combat | use composite material 3 in application

2022 free examination questions for hoisting machinery command and hoisting machinery command theory examination

Amway by head has this project management tool to improve productivity in a straight line

"Learning notes" recursive & recursive

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

Apple released a supplementary update to MacOS Catalina 10.15.5, which mainly fixes security vulnerabilities

How to quickly build high availability of service discovery
随机推荐
Bufferpool caching mechanism for executing SQL in MySQL
Correlation analysis summary
Esp-idf turns off serial port log output.
C # basic knowledge (1)
Design of logic level conversion in high speed circuit
Alibaba cloud container service differentiation SLO hybrid technology practice
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
Current detection circuit - including op amp current scheme
2022.02.14
Hcip day 12 notes
Tencent interview: can you find the number of 1 in binary?
股票開戶傭金最低的券商有哪些大家推薦一下,手機上開戶安全嗎
How to make recv have a little temper?
Pytorch learning notes 5: model creation
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
2022 t elevator repair registration examination and the latest analysis of T elevator repair
URLEncoder. Encode and urldecoder Decode processing URL
Qtoolbutton available signal
Day30-t540-2022-02-14-don't answer by yourself