绵阳东辰国际test10.12
蒟蒻分析:考试时写个权值线段树就是调不出来
蒟蒻总结:平时多练手
solution:其实就用树状数组维护一下就行
多了个撤销操作而已,应该十分钟就写完的,我写了三个小时!!!
code by jklover
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int out=0,sgn=1;
char jp=getchar();
while(jp!='-' && (jp<'0' || jp>'9'))
jp=getchar();
if(jp=='-')
sgn=-1,jp=getchar();
while(jp>='0' && jp<='9')
out=out*10+jp-'0',jp=getchar();
return out*sgn;
}
const int P=1e9+7;
int mul(int a,int b)
{
return 1LL * a * b % P;
}
const int MAXN=2e5+10;
int n,ecnt=0,head[MAXN],nx[MAXN<<1],to[MAXN<<1];
int pw[MAXN],ans=1;
void addedge(int u,int v)
{
++ecnt;
to[ecnt]=v;
nx[ecnt]=head[u];
head[u]=ecnt;
}
#define lowbit(x) x&(-x)
int bit[MAXN];
void add(int x,int c)
{
for(;x<=n;x+=lowbit(x))
bit[x]+=c;
}
int query(int x)
{
int s=0;
for(;x;x-=lowbit(x))
s+=bit[x];
return s;
}
void dfs(int u,int fa)
{
int t=query(u-1);
ans=mul(ans,pw[t]);
for(int i=head[u];i;i=nx[i])
{
int v=to[i];
if(v==fa)
continue;
add(v,1);
dfs(v,u);
add(v,-1);
}
}
int main()
{
freopen("dfs.in","r",stdin);
freopen("dfs.out","w",stdout);
n=read();
pw[0]=1;
for(int i=1;i<n;++i)
{
int u=read(),v=read();
addedge(u,v);
addedge(v,u);
pw[i]=mul(pw[i-1],2);
}
dfs(1,0);
cout<<ans<<endl;
return 0;
}
未完待续。。。。。