#include<iostream>
#include<deque>
#include<vector>
#include<cstring>
#define INF 0x7f
using namespace std;
vector<vector<int>> graph[2501];
vector<int> a;
int n, m, s, t, dis[2501], pre[2501], f1, f2, w, u, v;
bool exist[2501];
deque<int> team;
int main(){
ios::sync_with_stdio(false);
memset(dis, INF, sizeof(dis));
memset(exist, false, sizeof(exist));
cin >> n >> m >> s >> t;
for(int i = 0;i < m;i++){
cin >> f1 >> f2 >> w;
a.clear();
a.push_back(f2);
a.push_back(w);
graph[f1].push_back(a);
a.clear();
a.push_back(f1);
a.push_back(w);
graph[f2].push_back(a);
}
dis[s] = 0;
team.push_back(s);
exist[s] = true;
do{
u = team[0];
team.pop_front();
for(int i = 0;i < graph[u].size();i++){
v = graph[u][i][0];
if(dis[v] > dis[u]+graph[u][i][1]){
dis[v] = dis[u]+graph[u][i][1];
pre[v] = u;
if(!exist[v]){
team.push_back(v);
exist[v] = true;
}
}
}
}while(!team.empty());
cout << dis[t] << endl;
return 0;
}
脑回路太清奇导致无法套用其他犇犇在题解里的算法
求教