Count of bzoj4401 blocks

Source: Internet
Author: User

First determine a root after Dfs again, count the number of points per subtree, and then enumerate the n factor x, count the number of sub-tree points number is a multiple of the current enumeration factor X, if there is a n/x subtree satisfies the condition, then answer +1

Code

  

1#include <cstdio>2#include <algorithm>3#include <Set>4 #defineFi first5 #defineSC Second6 #defineMP Make_pair7 #defineN 20001008 using namespacestd;9 intP[n],pre[n],tt[n],s[n],cnt[n];Ten intn,i,a,b,j,ans,dp,sum; One voidLinkintXinty) A { -dp++;p re[dp]=p[x];p [x]=dp;tt[dp]=y; - } the voidDfsintXintFA) - { -     intI=P[x]; -s[x]=1; +      while(i) -     { +         if(tt[i]!=FA) A         { at DFS (tt[i],x); -s[x]+=S[tt[i]]; -         } -I=Pre[i]; -     } - } in intMain () - { toscanf"%d",&n); +      for(i=1; i<n;i++) -     { thescanf"%d%d",&a,&b);  * Link (A, b); $ link (b,a);Panax Notoginseng     } -Dfs1,0); the      for(i=1; i<=n;i++) +cnt[s[i]]++; A      for(i=1; i<=n;i++) the     if(n%i==0) +     { -sum=0; $          for(j=i;j<=n;j+=i) $sum+=Cnt[j]; -         if(sum==n/i) ans++; -     } theprintf"%d\n", ans); -}

Count of bzoj4401 blocks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.