#define _USE_MATH_DEFINES #include using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; typedef pair P; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } templatevoid Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);} const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2; //template end vector> g; int b[200010]; int dfs(int v,int p){ if(g[v].size()==0)return b[v]=1; int res=1; for(P x:g[v])if(x.first!=p){ res+=dfs(x.first,v); } return b[v]=res; } int main(){ int n; scanf("%d",&n); g.resize(n); vector> es; rep(i,0,n-1){ int u,v,w; scanf("%d%d%d",&u,&v,&w); u--; v--; g[u].push_back({v,w}); g[v].push_back({u,w}); es.push_back({u,{v,w}}); } ll ans=0; dfs(0,-1); rep(i,0,n)cerr<