把dis数组改成long long int就#4wa,不改就#31wa
#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
using namespace std;
typedef pair<int,int> PII;
const int N = 1e6 + 10;
int n,m;
int h[N],e[N],ne[N],idx;
long long w[N];
bool st[N];
long long int dis[N];
int Prev[N];
void add(int a,int b,int c){
e[idx] = b,ne[idx] = h[a],w[idx] = c,h[a] = idx++;
}
void dijkstra(){
priority_queue<PII,vector<PII>,greater<PII>>heap;
heap.push({0,1});
memset(dis,0x3f,sizeof dis);
dis[1] = 0;
while(heap.size()){
auto t = heap.top();
heap.pop();
int ver = t.second,distance = t.first;
if(st[ver])continue;
st[ver] = true;
for(int i = h[ver];i != -1;i = ne[i]){
int j = e[i];
if(dis[j] > dis[ver] + w[i]){
dis[j] = dis[ver] + w[i];
heap.push({dis[j],j});
Prev[j] = ver;
}
}
}
}
int main(){
memset(h,-1,sizeof h);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
while(m--){
int a,b,c;
cin >> a >> b >> c;
add(a,b,c),add(b,a,c);
}
dijkstra();
if(dis[n] == 0x3f3f3f3f)cout << -1;
else {
vector<int> ans;
ans.push_back(n);
while(Prev[n]){
n = Prev[n];
ans.push_back(n);
}
for(int i = ans.size() - 1;i >= 0;i--)cout << ans[i] << " ";
}
return 0;
}