Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //source : munim
- //http://codeforces.com/contest/343/submission/25460356
- #include<bits/stdc++.h>
- using namespace std;
- #define si(n) scanf("%d",&n)
- #define MAX 1000006
- #define INF 100000
- int n,st[MAX],en[MAX],par[MAX],cnt=0;
- vector<int>gr[MAX];
- int tree[4*MAX],prop[4*MAX];
- void go(int now,int p)
- {
- st[now]=++cnt;
- par[now]=p;
- for(int i=0;i<gr[now].size();i++){
- int to=gr[now][i];
- if(to==p)continue;
- go(to,now);
- }
- en[now]=cnt;
- }
- void push_down(int node)
- {
- tree[node*2]=tree[node*2+1]=prop[node*2]=prop[node*2+1]=prop[node];
- prop[node]=0;
- }
- void update(int node,int tl,int tr,int l,int r,int val)
- {
- if(tl>r || tr<l)return;
- if(tl>=l && tr<=r){
- tree[node]=val;
- if(val)prop[node]=val;
- return ;
- }
- if(prop[node])push_down(node);
- int mid=(tl+tr)/2;
- update(node*2,tl,mid,l,r,val);
- update(node*2+1,mid+1,tr,l,r,val);
- tree[node]=min(tree[node*2],tree[node*2+1]);
- return ;
- }
- int quary(int node,int tl,int tr,int l,int r)
- {
- if(tl>r || tr<l)return INF;
- if(tl>=l && tr<=r)
- return tree[node];
- if(prop[node])return prop[node];
- int mid=(tl+tr)/2,p1,p2;
- p1=quary(node*2,tl,mid,l,r);
- p2=quary(node*2+1,mid+1,tr,l,r);
- return min(p1,p2);
- }
- int main()
- {
- //freopen("input.txt","r",stdin);
- int i,j,n,q;
- si(n);
- for(i=1;i<n;i++){
- int u,v;
- si(u);si(v);
- gr[u].push_back(v);
- gr[v].push_back(u);
- }
- go(1,-1);
- //memset(prop,-1,sizeof(prop));
- si(q);
- while(q--){
- int c,v;
- si(c);si(v);
- if(c==1){
- if(v !=1 && quary(1,1,n,st[v],en[v])==0)
- update(1,1,n,st[par[v]],st[par[v]],0);
- update(1,1,n,st[v],en[v],1);
- }
- else if(c==2){
- update(1,1,n,st[v],st[v],0);
- }
- else {
- printf("%d\n",quary(1,1,n,st[v],en[v]));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement