// Problem: P4551 最长异或路径 // Contest: Luogu // URL: https://www.luogu.com.cn/problem/P4551 // Memory Limit: 64 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h> usingnamespace std; //#define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} //#define M //#define mo #define N 100010 structnode { int x, y, z, n; }dx[N*2]; structNode { int s[2]; }d[N*30]; int n, m, i, j, k; int dp[N], u, v, w, h[N]; int ans, cnt;
voidcun(int x, int y, int z) { dx[++k].x=x; dx[k].y=y; dx[k].z=z; dx[k].n=h[x]; h[x]=k; }
voiddfs(int x, int fa) { for(int g=h[x]; g; g=dx[g].n) { int y=dx[g].y; if(y==fa) continue; dp[y]=dp[x]^dx[g].z; dfs(y, x); } }
voidtrie(int x) { int i, j, p=1; for(i=30; i>=0; --i) { j=(x&(1<<i))>0; if(!d[p].s[j]) d[p].s[j]=++cnt; p=d[p].s[j]; } }
intfind(int dep, int x, int p) { if(dep<0) return0; int i=(x&(1<<dep))>0; returnfind(dep-1, x, (d[p].s[i^1] ? d[p].s[i^1] : d[p].s[i]) )+(d[p].s[i^1] ? (1<<dep) : 0); }