Submission

Status:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

Score: 100

User: KotatsuCat

Problemset: Sirabyrinth 6

Language: cpp

Time: 0.007 second

Submitted On: 2025-03-06 21:53:44

#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>

using namespace std;

const int mxN = 2e4+1;
const ll inf = 2e9+1;
vector<pii> g[mxN];

ll dfs(int u, int p){
    ll res = 0;
    for(auto &[v, w]:g[u]){
        if(v==p) continue;
        res = max(res, dfs(v, u)+w);
    }
    return res;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int n,k;
    ll ans = 0;
    cin >> n >> k;
    for(int i=1;i<n;i++){
        int u,v,w;
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
        ans+=w;
    }
    ans<<=1;
    cout << ans-dfs(k, -1);

    return 0;
}