Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * ####### # *
- * # # # ###### # # # # #### # # # # # *
- * # # # # # # ## # # # # # # # *
- * # ###### ##### # # # # # #### ###### # # # *
- * # # # # ####### # # # # # # # # # *
- * # # # # # # # ## # # # # # # # *
- * # # # ###### # # # # #### # # #### ###### *
- ***************************************************************************/
- #include<bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define endl '\n'
- #define pii pair<ll int,ll int>
- #define vi vector<ll int>
- #define all(a) (a).begin(),(a).end()
- #define F first
- #define S second
- #define sz(x) (ll int)x.size()
- #define hell 1000000007
- #define rep(i,a,b) for(ll int i=a;i<b;i++)
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define bs binary_search
- #define mp make_pair
- using namespace std;
- #define N 100005
- vi ad[N];
- ll v[N];
- bool vis[N];
- ll xr[N];
- pii papa[N];
- ll srt;
- // ll tree[4*N];
- ll lazy[4*N];
- void dfs(ll node,ll par,ll pari)
- {
- papa[node].F=par;
- papa[node].S=pari+1;
- srt^=v[node];
- xr[node]=srt;
- vis[node]=1;
- for(auto i:ad[node])
- if(!vis[i])
- dfs(i,node,pari+1);
- srt^=v[node];
- return;
- }
- // void build(ll node,ll start,ll end)
- // {
- // if(start==end)
- // {
- // tree[node]=v[start];
- // }
- // ll mid=(start+end)/2;
- // build(2*node,start,mid);
- // build(2*node,mid+1,end);
- // }
- ll findingDaddy(ll node1,ll node2)
- {
- if(papa[node1].S>papa[node2].S)
- {
- while(papa[node1].S!=papa[node2].S)
- {
- node1=papa[node1].F;
- }
- }
- else
- {
- while(papa[node1].S!=papa[node2].S)
- {
- node2=papa[node2].F;
- }
- }
- while(node1!=node2)
- {
- node1=papa[node1].F;
- node2=papa[node2].F;
- }
- return(node1);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int TESTS=1;
- cin>>TESTS;
- while(TESTS--)
- {
- ll n,q,x,y;
- cin>>n;
- rep(i,1,n+1)
- cin>>v[i];
- rep(i,1,n)
- {
- cin>>x>>y;
- ad[x].pb(y);
- ad[y].pb(x);
- }
- dfs(1,-1,0);
- cin>>q;
- ll t;
- // rep(i,1,n+1)
- // cout<<xr[i]<<" ";
- // cout<<endl;
- // rep(i,1,n+1)
- // cout<<papa[i].F<<" ";
- // cout<<endl;
- // rep(i,1,n+1)
- // cout<<papa[i].S<<" ";
- // cout<<endl;
- rep(i,0,q)
- {
- cin>>t>>x>>y;
- // cout<<findingDaddy(x,y);
- if(t==1)
- {
- //need to work on update.
- }
- if(t==2)
- cout<<((xr[x]^xr[y])^(v[findingDaddy(x,y)]))<<endl;
- }
- rep(i,1,n+1)
- ad[i].clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement