https://www.acmicpc.net/problem/6248
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define fastio cin.tie(0)->sync_with_stdio(0)
#define sz(v) (int)(v).size()
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define compress(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define OOB(x, y) ((x) < 0 || (x) >= n || (y) < 0 || (y) >= m)
#define debug(x) cout << (#x) << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using ull = unsigned long long;
using dbl = double;
using ldb = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vs = vector<string>;
using tii = tuple<int,int,int>;
template<typename T> using wector = vector<vector<T>>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LNF = 1e18 + 7;
vector<pii> adj[1001];
vector<int> dijk(int st){
vector<int> dist(1001, INF);
priority_queue<pii,vector<pii>,greater<pii>> PQ;
dist[st] = 0;
PQ.push({dist[st], st});
while(!PQ.empty()){
auto [weight, cur] = PQ.top(); PQ.pop();
if(dist[cur] < weight) continue;
for(auto [nWeight, nxt] : adj[cur]){
if(dist[nxt] > nWeight + weight){
dist[nxt] = nWeight + weight;
PQ.push({dist[nxt], nxt});
}
}
}
return dist;
}
int main() {
fastio;
int n,m,x; cin >> n >> m >> x;
while(m--){
int a,b,c; cin >> a >> b >> c;
adj[a].pb({c, b});
adj[b].pb({c, a});
}
auto dist = dijk(x);
int mx = 0;
for(int i = 1; i <= n; i++) mx = max(mx,dist[i]);
cout << mx * 2 << "\n";
return 0;
}