#include<bits/stdc++.h> using namespace std; typedef long long int_t; int read() { int_t x=0,w=1; char ch=0; while(!isdigit(ch)) {ch = getchar();if(ch =='-')w=-1;} while(isdigit(ch)) x=___(1)___, ch=getchar(); return x; } struct E { int_t to,w; E(int_t to0, int_t w0) {to=to0; w=w0;} }; int_t ans; vector<E> G[501000]; int_t dfs(int_t rt, int_t fa) { int_t ret=0,cnt=0; for(E e: G[rt]) if(e.to != fa) { int_t res = dfs(e.to, rt)+ e.w; if (___(4)___) ans+=cnt*(res-ret),___(3)___,cnt++; else ___(2)___, cnt++; } return ret; } int main() { int_t n =read(), s = read(); for(int_t i=1; i<n; i++) { int_t u = read(), v = read(), w = read(); G[u].emplace_back(v, w); G[v].emplace_back(u, w); } ___(5)___ cout << ans; return 0 ; }