1129. 热浪
https://www.acwing.com/problem/content/1131/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int N=2510,M=6210*2;
int h[N],w[M],e[M],ne[M],idx;
int n,m,TS,TE;
int dist[N],st[N];
void add(int a,int b,int c){
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
void spfa(){
queue<int>q;
q.push(TS);
st[TS]=1;
dist[TS]=0;
while(q.size()){
int k=q.front();
st[k]=0;
q.pop();
for(int i=h[k];i!=-1;i=ne[i]){
int j=e[i];
if(dist[j]>dist[k]+w[i]){
dist[j]=dist[k]+w[i];
if(!st[j]){
st[j]=1;
q.push(j);
}
}
}
}
}
int main(){
cin>>n>>m>>TS>>TE;
memset(h,-1,sizeof h);
memset(dist,0x3f,sizeof dist);
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
add(a,b,c);
add(b,a,c);
}
spfa();
cout<<dist[TE]<<endl;
return 0;
}
// freopen("testdata.in", "r", stdin);
1128. 信使
https://www.acwing.com/problem/content/1130/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int N=105,M=205*2;
int h[N],w[M],e[M],ne[M],idx;
int n,m;
int dist[N],st[N];
void add(int a,int b,int c){
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
void spfa(){
queue<int>q;
q.push(1);
dist[1]=0;
while(q.size()){
int k=q.front();
st[k]=0;
q.pop();
for(int i=h[k];i!=-1;i=ne[i]){
int j=e[i];
if(dist[j]>dist[k]+w[i]){
dist[j]=dist[k]+w[i];
if(!st[j]){
st[j]=1;
q.push(j);
}
}
}
}
}
int main(){
cin>>n>>m;
memset(h,-1,sizeof h);
memset(dist,0x3f,sizeof dist);
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
add(a,b,c);
add(b,a,c);
}
spfa();
int res=0;
for(int i=1;i<=n;i++){
res=max(res,dist[i]);
}
if(res==0x3f3f3f3f) puts("-1");
else cout<<res<<endl;
return 0;
}
// freopen("testdata.in", "r", stdin);