bzoj1103: [POI2007]大都市meg
来源:互联网 发布:公务员上岸经验知乎 编辑:程序博客网 时间:2024/05/16 08:35
dfs序+树状数组维护;
#include<cstdio>#include<algorithm>#define rep(i,k,n) for(int i=k;i<=(n);i++)using namespace std;int read(){ int x=0;char ch=getchar(); while(ch<'0'||ch>'9')ch=getchar(); while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x;}const int N=250005;struct E{ int to,next;E(int to=0,int next=0):to(to),next(next){}}edge[2*N];int head[N],tot=0,n,l[N],r[N],m,tr[2*N],sta[2*N],top=0,cc[N],clock=0;void add(int x,int y){ edge[++tot]=E(y,head[x]);head[x]=tot; edge[++tot]=E(x,head[y]);head[y]=tot; }void Add(int x,int d){for(;x<=clock;x+=(x&-x))tr[x]+=d;}int Q(int x){int res=0;for(;x;x-=(x&-x))res+=tr[x];return res;}void dfs(){ sta[++top]=1; while(top){ int u=sta[top];if(!l[u])l[u]=++clock; for(int i=head[u];i;i=edge[i].next){ int v=edge[i].to; if(!l[v]){ sta[++top]=v;break; } }if(sta[top]==u){ top--;r[u]=++clock; } }}int main(){//freopen("in.in","r",stdin); n=read();int x,y; rep(i,1,n-1){ x=read();y=read();add(x,y); }dfs(); rep(i,2,n)Add(l[i],1),Add(r[i],-1); m=read();char s[20]; rep(i,1,n+m-1){ scanf("%s",s); if(s[0]=='A'){ x=read(),y=read(); Add(l[y],-1),Add(r[y],1); } else{x=read();printf("%d\n",Q(l[x]));} } }
0 0
- bzoj1103【POI2007】大都市meg
- 【POI2007】【BZOJ1103】大都市meg
- bzoj1103[POI2007]大都市meg
- 【BZOJ1103】【POI2007】大都市meg
- bzoj1103: [POI2007]大都市meg
- 【BZOJ1103】[POI2007]大都市meg
- bzoj1103: [POI2007]大都市meg
- bzoj1103 [POI2007]大都市meg
- BZOJ1103: [POI2007]大都市meg
- bzoj1103 [POI2007]大都市meg
- BZOJ1103: [POI2007]大都市meg
- 8.3 bzoj1103 [POI2007]大都市meg
- BZOJ1103 [POI2007]大都市meg 【树剖】
- 【bzoj1103】【POI2007】【大都市】【meg】【人工栈】
- 【bzoj1103】[POI2007]大都市meg DFS序
- bzoj1103: [POI2007]大都市meg(树链剖分)
- [BZOJ1103][POI2007]大都市meg(dfs序+bit||链剖)
- 【DFS序+线段树】BZOJ1103 [POI2007]大都市meg
- 【leetcode】Minimum Depth of Binary Tree
- B. Crossed ladders
- redis 使用
- 2326: [HNOI2011]数学作业
- 你真的会写单例模式吗——Java实现
- bzoj1103: [POI2007]大都市meg
- iOS程序猿之AFNetworking 3.0 版本使用
- 吐槽
- bzoj 3555: [Ctsc2014]企鹅QQ
- 简单几步解决 svchost 占用资源过高的问题
- Enhancing App Security on Google Play
- bzoj2631: tree
- 适配器
- 几何题,二分法 fz1148