hdu4705 Y
来源:互联网 发布:917发卡平台php源码 编辑:程序博客网 时间:2024/06/08 19:40
非连通组合个数=所有组合-连通组合个数
树形DP,根结点表示三个连通组合数的中间那个数
#include<iostream>#include<cstring>#include<cstdio>using namespace std;#define M 100010#pragma comment(linker, "/STACK:16777216")struct node{ int v,next;}edge[M*2];int head[M],tot;void insert(int u,int v){ edge[tot].v=v; edge[tot].next=head[u]; head[u]=tot++;}int n;long long ans;int dfs(int u,int pre){ int son,tmp=0,i,v; for(i=head[u];i!=-1;i=edge[i].next){ v=edge[i].v; if(v==pre) continue; son=dfs(v,u); tmp+=son; ans+=(long long)(n-tmp-1)*son; } return tmp+1;}int main(){ int u,v,i; while(scanf("%d",&n)!=EOF){ tot=0; ans=0; memset(head,-1,sizeof(head)); for(i=1;i<n;i++){ scanf("%d%d",&u,&v); insert(u,v); insert(v,u); } dfs(1,-1); long long sum=n*(n-1)*(n-2)/6; printf("%I64d\n",sum-ans); } return 0;}
- hdu4705 Y
- HDU4705 - Y (树形DP)
- hdu4705 Y--树形dp
- 树形DP(简单题)(Y HDU4705)
- hdu4705(树形DP)
- hdu4705(树形dp)
- HDU4705-杭电多校第十场1010
- y
- y
- Y
- Y
- Y
- Y
- y
- Y
- Y
- y
- Y
- HDU 3586 Information Disturbing
- UILabel的相关属性设置
- windows 下使用vim
- 积攒自己用过的js时间插件
- Cocos2d游戏学习之主角不动
- hdu4705 Y
- win8 网络受限解决
- 由SAT问题展开说(1) (转)
- Codeforces Round #199 (Div. 2) A. Xenia and Divisors
- 对比DML操作产生的REDO及UNDO大小
- Android03
- java串口通信API说明
- zoj 1649 Rescue
- HDU 3790 最短路径