voidinsert(int x){ int now = 1; for(int i = 30; i >= 0; i --){ int t = ((x >> i) & 1); //取出二进制上第i位的数 if(ch[now][t]) now = ch[now][t]; //如果有的话,就直接走过去即可 else { ch[now][t] = ++ cnt; //否则就新建一个 now = ch[now][t]; } } }
intquery(int x){ int now = 1 , ans = 0; for(int i = 30; i >= 0; i --){ int t = ((x >> i) & 1); if(ch[now][t ^ 1]) now = ch[now][t ^ 1] , ans = (1 << i); //如果两个二进制数可以不同,则设为不同,且记录答案 else now = ch[now][t]; //否则只能相同了 } return ans; }
#define I inline #define fi first #define se second #define pb push_back #define MP make_pair #define PII pair<int , int> #define PSL pair<string , long long> #define PLL pair<long long , long long> #define all(x) (x).begin() , (x).end() #define copy(a , b) memcpy(a , b , sizeof(b)) #define clean(a , b) memset(a , b , sizeof(a)) #define rep(i , l , r) for (int i = (l); i <= (r); i ++) #define per(i , r , l) for (int i = (r); i >= (l); i --) #define PE(i , x) for(int i = head[x]; i; i = edge[i].last) #define DEBUG(x) std :: cerr << #x << '=' << x << std :: endl
typedeflonglong ll; typedefunsignedlonglong ull;
template <classT> inlinevoidread(T &x){ char c = getchar(), f = 0; x = 0; while (!isdigit(c)) f = (c == '-'), c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x = f ? -x : x; }
usingnamespacestd;
constint N = 10000 + 5; constint M = 100000 + 5; constint HA = 998244353;
structEdge{ int to , last; ll dis; }edge[M << 1];
int edge_num; int head[M << 1];
I voidadd_edge(int from , int to , ll dis){ edge[++ edge_num] = (Edge){to , head[from] , dis}; head[from] = edge_num; edge[++ edge_num] = (Edge){from , head[to] , dis}; head[to] = edge_num; }
int fa[M] , dis[M];
voiddfs(int x , int f){ fa[x] = f; PE(i , x){ int to = edge[i].to; if(to == f) continue; dis[to] = (dis[x] ^ edge[i].dis); dfs(to , x); } }
namespace Trie{ #define lson(x) ch[x][0] #define rson(x) ch[x][1] int ch[M << 5][2] , cnt = 1; voidinsert(int x){ int now = 1; per(i , 30 , 0){ int t = ((x >> i) & 1); if(ch[now][t]) now = ch[now][t]; else ch[now][t] = ++ cnt , now = ch[now][t]; } } intquery(int x){ int now = 1 , ans = 0; per(i , 30 , 0){ int t = ((x >> i) & 1); if(ch[now][t ^ 1]) now = ch[now][t ^ 1] , ans += (1 << i); else now = ch[now][t]; } return ans; } #undef lson #undef rson }
usingnamespace Trie;
intmain(){ #ifdef LOCAL freopen("try.in" , "r" , stdin); freopen("try1.out" , "w" , stdout); #endif int n; read(n); rep(i , 1 , n - 1){ int u , v; ll w; read(u) , read(v) , read(w); add_edge(u , v , w); } dis[1] = 0; dfs(1 , 0); rep(i , 1 , n){ insert(dis[i]); } ll res = 0; rep(i , 1 , n){ res = max(res , 1ll * query(dis[i])); } printf("%d\n" , res); return0; }
for(int i = 1; i <= n; i ++){ int cnt = 0 , x = i; do{ val[x] ^= (cnt + v[i]); cnt ++; x = fa[x]; }while(x); } ll ans = 0; for(int i = 1; i <= n; i ++) ans += val[i]; printf("%lld\n" , ans);
#define I inline #define fi first #define se second #define pb push_back #define MP make_pair #define PII pair<int , int> #define PSL pair<string , long long> #define PLL pair<long long , long long> #define all(x) (x).begin() , (x).end() #define copy(a , b) memcpy(a , b , sizeof(b)) #define clean(a , b) memset(a , b , sizeof(a)) #define rep(i , l , r) for (int i = (l); i <= (r); i ++) #define per(i , r , l) for (int i = (r); i >= (l); i --) #define PE(i , x) for(int i = head[x]; i; i = edge[i].last) #define DEBUG(x) std :: cerr << #x << '=' << x << std :: endl
typedeflonglong ll; typedefunsignedlonglong ull;
template <classT> inlinevoidread(T &x){ char c = getchar(), f = 0; x = 0; while (!isdigit(c)) f = (c == '-'), c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x = f ? -x : x; }
usingnamespacestd;
constint N = 10000 + 5; constint M = 530000 + 5; constint HA = 998244353;
int n , val[M];
structEdge{ int to , last; }edge[M << 1];
int edge_num; int head[M << 1];
I voidadd_edge(int from , int to){ edge[++ edge_num] = (Edge){to , head[from]}; head[from] = edge_num; edge[++ edge_num] = (Edge){from , head[to]}; head[to] = edge_num; }