#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; int n; vector

g[200020]; ll w[200020]; int cnt[200020]; bool used[200020]; ll ans; void dfs(int x){ used[x]=1; cnt[x]=1; for(auto p:g[x]){ int y=p.first; if(used[y]) continue; dfs(y); cnt[x]+=cnt[y]; ans+=2*(ll)(n-cnt[y])*(ll)cnt[y]*w[p.second]; } } int main() { cin>>n; for(int i=0; i>u>>v>>w[i]; u--; v--; g[u].push_back({v, i}); g[v].push_back({u, i}); } dfs(0); cout<