1 struct DSU 2 { 3 int fa[MAXN]; 4 vector<int> base[MAXN]; 5 void add(int tar,int x) 6 { 7 for(auto &t:base[tar]) 8 x=min(x,x^t); 9 if(!x)return; 10 for(auto &t:base[tar]) 11 t=min(t,t^x); 12 base[tar].push_back(x); 13 } 14 int query(int tar) 15 { 16 int res=0; 17 for(auto &t:base[tar]) 18 res=max(res,res^t); 19 return res; 20 } 21 void init(int n) 22 { 23 for(int i=1;i<=n;i++) 24 fa[i]=i,add(i,a[i]); 25 } 26 int find(int x) 27 { 28 return fa[x]==x ? x : fa[x]=find(fa[x]); 29 } 30 void merge(int x,int y) 31 { 32 x=find(x),y=find(y); 33 if(x==y)return; 34 fa[x]=y; 35 for(auto &v:base[x])add(y,v); 36 base[x].clear(); 37 } 38 int answer(int x) 39 { 40 x=find(x); 41 return query(x); 42 } 43 }dsu;