1. 程式人生 > >【BubbleCup X】E:Casinos and travel

【BubbleCup X】E:Casinos and travel

xor namespace getchar clas read line 額外 def har

懶得一起寫blog了,反正沒人看,分著寫。

這個題看上去像個dp計數,其實這麽想,題意就是根到葉子的xor和=0

分治節點可以隨意調整,只有葉子節點的取值會對答案造成影響。

也就是每個點做根時,分支節點產生的方案貢獻是2cnt,此處cnt是分支節點個數。

如果是葉子做根額外多一次冪,因為這個葉子節點被固定了。

#include<bits/stdc++.h>
const int N=1000005;
const int yql=1e9+7;
typedef long long ll;
using namespace std;
int ind[N],n,m,cnt=0;ll ans=0,bin[N];
inline 
int read(){ int f=1,x=0;char ch; do{ch=getchar();if(ch==-)f=-1;}while(ch<0||ch>9); do{x=x*10+ch-0;ch=getchar();}while(ch>=0&&ch<=9); return f*x; } int main(){ n=read(); for(int i=1;i<n;i++){ int u=read(),v=read(); ind[u]++;ind[v]++; } bin[
0]=1;cnt=0; for(int i=1;i<=n*10;i++)bin[i]=(bin[i-1]<<1)%yql; for(int i=1;i<=n;i++)if(ind[i]!=1)cnt++; for(int i=1;i<=n;i++)ans=(ans+bin[cnt+(ind[i]==1)])%yql; ans=(ans+yql)%yql; printf("%lld\n",ans); }

【BubbleCup X】E:Casinos and travel