jy20091121 @ 2024-05-30 19:19:53
#include<bits/stdc++.h>
using namespace std;
#define PLL pair<int,int>
int che[1320302];
int vis[1032032];
int e[1302302],ne[1000031],h[2120002],w[2130032];
int n,m,s;
int idx;
int add(int a,int b,int c){
e[idx]=b,ne[idx]=h[a],w[idx]=c,h[a]=idx++;
}
int ddd(int s){
memset(vis,0x3f,sizeof vis);
priority_queue<PLL,vector<PLL>,greater<PLL> > heap;
vis[s]=0;
heap.push({0,s});
while(heap.size()){
auto t=heap.top();
int bh=t.first;
int jl=t.second;
heap.pop();
if(che[bh]) continue;
che[bh]=1;
for(int i=h[bh];i!=-1;i=ne[i]){
int j=e[i];
if(jl+w[i]<vis[j]){
vis[j]=jl+w[i];
heap.push({vis[j],j});
}
}
}
}
int main(){
memset(h,-1,sizeof h);
cin>>n>>m;
cin>>s;
for(int i=1;i<=m;i++) {
int a,b,c;
cin>>a>>b>>c;
add(a,b,c);
}
ddd(s);
for(int i=1;i<=n;i++){
cout<<vis[i]<<" ";
}
return 0;
}