#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; class Dis{ public: vector rank,p,siz; Dis(int s){ rank.resize(s,0); p.resize(s,0); siz.resize(s,1); rep(i,s) makeSet(i); } void makeSet(int x){ p[x]=x; rank[x]=0; } bool same(int x,int y){ return findSet(x)==findSet(y); } void unite(int x,int y){ if(same(x,y)) return; link(findSet(x),findSet(y)); } void link(int x,int y){ if(rank[x]>rank[y]){ p[y]=x; siz[x]+=siz[y]; } else{ p[x]=y; siz[y]+=siz[x]; if(rank[x]==rank[y]) rank[y]++; } } int findSet(int x){ if(x != p[x]) p[x]=findSet(p[x]); return p[x]; } int size(int x){ return siz[findSet(x)]; } }; const int MOD=1e9+7; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; vector A(n-1),B(n-1),C(n-1); rep(i,n-1){ cin>>A[i]>>B[i]>>C[i]; A[i]--,B[i]--; } ll ans=0; ll c=1; rep(i,31){ Dis ds=Dis(n); rep(j,n-1){ if(C[j]&(1<