#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define faster() ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
typedef pair<int,int> ii ;
int n , m , s ;
vector<ii> ke[200005];
bool visited[200005];
struct Edge{
int u , v , w ;
};
vector<Edge> dsCanh ;
void BellmanFord(int s){
vector<int> d(n + 1 , 1e9);
d[s] = 0 ;
for(int i = 1 ; i <= n - 1 ; i++){
for(Edge e : dsCanh){
int u = e.u ;
int v = e.v ;
int w = e.w ;
if(d[u] < 1e9){
d[v] = min(d[v] , d[u] + w);
}
}
}
for(int i = 1 ; i <= n ; i++){
cout << d[i] << " ";
}
}
void solve(){
cin >> n >> m >> s ;
for(int i = 1 ; i <= m ; i++){
int x , y, w ; cin >> x >> y >> w ;
ke[x].push_back({y , w});
ke[y].push_back({x , w});
// them ca 2 canh vao dsCanh
dsCanh.push_back({x , y, w});
dsCanh.push_back({y , x, w});
}
BellmanFord(s);
}
signed main() {
faster();
int test = 1 ;
// cin >> test ;
while(test--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZW5kbCAiXG4iCiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIGZhc3RlcigpIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZShudWxscHRyKTsgY291dC50aWUobnVsbHB0cik7Cgp0eXBlZGVmIHBhaXI8aW50LGludD4gaWkgOwoKaW50IG4gICwgbSAsIHMgOwp2ZWN0b3I8aWk+IGtlWzIwMDAwNV07CmJvb2wgdmlzaXRlZFsyMDAwMDVdOwpzdHJ1Y3QgRWRnZXsKICAgIGludCB1ICwgdiAsIHcgOwp9Owp2ZWN0b3I8RWRnZT4gZHNDYW5oIDsKCgp2b2lkIEJlbGxtYW5Gb3JkKGludCBzKXsKICAgIHZlY3RvcjxpbnQ+IGQobiArIDEgLCAxZTkpOwogICAgZF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