#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> P;
static const int INF=1<<24;


struct ED{
	int s,t,d;
};

bool operator<(ED a,ED b){
	return a.d>b.d;
}


int main(){
	int V,E,r,s,t,d;
	vector<vector<ED> > v(100010);
	int vmin[100010];
	int vis[100010];
	priority_queue<ED> pq;
	cin>>V>>E>>r;
	rep(i,E){
		cin>>s>>t>>d;
		ED t1,t2;
		t1.s=s; t1.t=t; t1.d=d;
		t2.s=t; t2.t=s; t2.d=d;
		v[s].PB(t1);
		v[t].PB(t2);
	}
	rep(i,100010){
		vmin[i]=INT_MAX;
		vis[i]=0;
	}
	vmin[r]=0;
	vis[r]=1;
	rep(i,v[r].size()){
		pq.push(v[r][i]);
	}
	
	while(!pq.empty()){
		ED tmp=pq.top();
		pq.pop();
		//cout<<"tmp "<<tmp.s<<" "<<tmp.t<<" "<<tmp.d<<endl;
		vmin[tmp.t]=min(vmin[tmp.s]+tmp.d,vmin[tmp.t]);
		vis[tmp.t]=1;
		//cout<<tmp.t<<endl;
		rep(i,v[tmp.t].size()){
			//cout<<vis[v[tmp.t][i].t]<<endl;
			if(vis[v[tmp.t][i].t]==0){
				//cout<<"hoge\n";
				pq.push(v[tmp.t][i]);
				//cout<<"v "<<v[tmp.t][i].s<<" "<<v[tmp.t][i].t<<" "<<v[tmp.t][i].d<<endl;
			}
		}
	}
	rep(i,100010){
		if(vis[i]==1){
			cout<<vmin[i]<<endl;
		}
	}
	 return 0;
}