#include using namespace std; using ll = long long; const int MOD = 1000000007; struct UnionFind { vector par; // 各元の親を表す配列 vector siz; // 素集合のサイズを表す配列(1 で初期化) vector edge; // Constructor UnionFind(ll sz_): par(sz_), siz(sz_, 1LL), edge(sz_) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) { edge[x]++; return false; } // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; edge[x] += edge[y] + 1; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } ll cnt_edge(ll x) { return edge[root(x)]; } }; int main() { int N; cin >> N; vector> edge(N-1); vector C(N-1); for(int i = 0; i < N-1; i++) { int a,b; cin >> a >> b; a--,b--; edge[i] = {a,b}; cin >> C[i]; } long long ans = 0; for(int i = 0; i < 40; i++) { UnionFind UT(N); for(int j = 0; j < N-1; j++) { if(C[j] & (1LL<