题目大意:给出一棵树,告诉点与点之间的关系和每个点上的权值,询问对于每个点的子树的所有点上的值与给定数字的异或的最大值是多少。
异或求最大值,用01字典树来维护,至于子树的问题,用dfs序维护一下每棵子树的出入信息,在查询的时候用出子树的点减去入子树的点的前一个点,只要该某个节点上仍然有节点经过即可。其余就和普通的01字典树求异或差不多了
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
const int N=1000005;
vector<int>vec[N];//存图
int num[N];
int tot1;//树的节点序号
int tot2;//字典树的节点序号
int in[N],out[N];
struct ress
{
int sum[2];//每个点经过的数目
int son[2];//左右子节点序号信息
}tree[N*50];
int t[N];//每棵字典树的节点信息
int ans=0;
void init(int n)
{
tot1=tot2=0;
t[0]=0;
for(int i=1;i<=n;i++)
vec[i].clear();
}
void build(int pre,int now,int val,int deep)
{
if(deep<0)
return ;
int temp=!!(val&(1<<deep));
tree[now]=tre