SRM 559 Div1 500 HatRack
2017-04-30 19:26
375 查看
/* 计算出每个节点对应子树的方法相乘即可 */ #include<bits/stdc++.h> using namespace std; typedef long long ll; #define M 55 int n,ch[M][M]; vector<int>G[M]; ll dfs(int x,int f=0,int p=1){ ch[x][0]=0; for(int i=0;i<G[x].size();i++)if(G[x][i]!=f) ch[x][++ch[x][0]]=G[x][i]; if(ch[x][0]==0&&p*2>n)return 1; if(ch[x][0]==1&&p*2==n)return dfs(ch[x][1],x,p<<1); if(ch[x][0]==2){ int l1=dfs(ch[x][1],x,p<<1); int r2=dfs(ch[x][2],x,p<<1|1); int l2=dfs(ch[x][2],x,p<<1); int r1=dfs(ch[x][1],x,p<<1|1); return 1ll*l1*r2+l2*r1; }return 0; } int main(){ scanf("%d",&n); for(int i=1,x,y;i<n;i++){ scanf("%d%d",&x,&y); G[x].push_back(y);G[y].push_back(x); }ll ans=0; for(int i=1;i<=n;i++)ans+=dfs(i); cout<<ans<<'\n'; }
相关文章推荐
- 【TP SRM 703 div2 500】 GCDGraph
- TopCoder SRM 655 Div2 Problem 500 - FoldingPaper2 (思维)
- topcoder SRM 548 DIV2 500
- TopCoder SRM 649 Div2 Problem 500 - CartInSupermarketEasy (区间DP)
- SRM 497(DIVII) 500 PermutationSignature
- SRM 500 DIV1 B
- SRM 667 DIV2 OrderOfOperationsDiv2 500-point
- SRM 586 DIV2 500
- TC SRM 671 Div2 500 BearDartsDiv2
- TopCoder SRM 653 Div2 Problem 500 - RockPaperScissorsMagicEasy (DP)
- srm 556 div1 500 LeftRightDigitsGame2(DP)
- Topcoder SRM 660 DIV1 500 Privateparty(数学)
- SRM500 DIV Ⅰ
- TopCoder SRM 681 Div. 2 Problem 500 - ExplodingRobots (枚举)
- SRM 542 DIV1 500 StrangeDictionary2
- Topcoder SRM 660 DIV1 500 Privateparty(数学,容斥)
- SRM 719 Div 1 250 500
- SRM 559 div 2【AK】
- TopCoder SRM 663 Div2 Problem 500 - ABBA (思维)
- SRM 562 Div1 500 CheckerFreeness