题目大意:
给你一棵\(n\)个节点的树,每个节点都有一个小于\(m\)的权值 定义一棵子树的权值为所有节点的异或和,问权值为\(0..m−1\)的所有子树的个数设\(f[i][j]\)表示节点\(i\)及其子树中异或和为\(j\)的方案数,发现合并答案的过程就是两个异或卷积,用\(FWT\)优化即可
//minamoto#include#include #define R register#define ll long long#define mem(a) memset(a,0,sizeof(a))#define fp(i,a,b) for(R int i=a,I=b+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)using namespace std;char buf[1<<21],*p1=buf,*p2=buf;inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}int read(){ R int res,f=1;R char ch; while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1); for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); return res*f;}const int N=(1<<10)+5,P=1e9+7,inv=500000004;inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}struct eg{int v,nx;}e[N<<1];int head[N],tot;inline void add_edge(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}int n,m,lim,x,u,v,f[N][N],ans[N];void FWT(int *A,int ty){ for(R int mid=1;mid <<=1) for(R int j=0;j <<1)) for(R int k=0;k