Idea: First of all, we need to divide the tree points. If the root node is root, this problem is solved by finding the valid root path. Because we can use sub-governance to enumerate the root, and add the number of paths of all the root to the result. Of course, the root here is not the root of the entire tree, it is the child root.
We assign each node an array of 30 characters to record the number of times a given factor occurs in each node's weight value. If the three root values of the values multiplied by several weights are still integers, the power of Value must be a multiple of 3. Through this conversion, we take the remainder of all power pairs 3, and the result is the same.
When determining the number of valid paths that pass through the root user, we enter a sub-tree and add the power of the path factor to determine whether there is an opposition. If yes, the result is + 1. The opposite state is the State that can synthesize valid paths.
For example, the factor is 2, 3, 5.
Then, if the status of the x node is 0, 1, 2 indicates the power of 0, 3, and 5.
The opposite state is 0, 2, 1. Because after the two paths are merged, the values 0, 3, and 3 are all multiples of 3.
Number of status records. We can use a long map.
Stack is required, otherwise RE is required. I have two RESS in a row, and the AC is added.
comment(linker, "/STACK:1024000000,1024000000")<iostream><cstring><algorithm><cstdio><cmath><vector><map> Maxn 100010 Maxm 200010 LL __int64 inf 0x7fffffff <LL,LL> head[Maxn],vi[Maxn],e,ans,num,k,n,m,prime[ cnt[<Node>,-,,,]=( i=;i<=;i++=Exp[i-]*=ans=lans= add( u,=u,edge[e].v=v,edge[e].next=head[u],head[u]=e++=v,edge[e].v=u,edge[e].next=head[v],head[v]=e++ dfssize( u,==(i=head[u];i!=-;i==(v!=fa&&!+=(size[v]>mx[u]) mx[u]= dfsroot( r, u,(size[r]-size[u]>mx[u]) mx[u]=size[r]-(mx[u]<mi) mi=mx[u],root=(i=head[u];i!=-;i==(v!=fa&&! dfsdis( u,Node d,=(j=;j<=k;j++)+=(-(d.cnt[j]+node[root].cnt[j])%)%*+=hash[cc];(i=head[u];i!=-;i==(v!=fa&&!(j=;j<=k;j++=(d.cnt[j]+node[v].cnt[j])% calc( i,j,ret==]=(i=head[u];i!=-;i==(!= ( r=;r<sz;r++)=(j=;j<=k;j+++=q[r].cnt[j]*++ dfs(=+= vi[root]=(i=head[root];i!=-;i==(!(scanf(,&n)!=,&(i=;i<=k;i++,&(i=;i<=n;i++,&,(j=;j<=k;j++(x%prime[j]==&&x!=++%=/=(x== cc=(j=;j<=k;j+++=(cc==++ (i=;i<n;i++,&u,&