洛谷P2899 [USACO08JAN]手机网络Cell Phone Network
来源:互联网 发布:iphone铃声制作软件 编辑:程序博客网 时间:2024/06/05 21:49
#include<bits/stdc++.h>#define N 100100using namespace std;const int INF=1008610086;int A[N],B[N],C[N];int beg[N],to[N],nex[N];int n,len;inline void Add(int a,int b){ nex[++len]=beg[a],beg[a]=len,to[len]=b; nex[++len]=beg[b],beg[b]=len,to[len]=a;}void dfs(int p,int fa){ A[p]=B[p]=C[p]=0;int mib=1;int f=0;for(int i=beg[p];i;i=nex[i]){if(to[i]==fa) continue;dfs(to[i],p);if(A[to[i]]<=B[to[i]]){A[p]+=A[to[i]];mib=min(mib,B[to[i]]-A[to[i]]);}else A[p]+=B[to[i]],f=1;C[p]+=min(B[to[i]],A[to[i]]);B[p]+=min(C[to[i]],min(B[to[i]],A[to[i]]));}B[p]++;if(!f) A[p]+=mib;if(!A[p]) A[p]=1;}int main(){ scanf("%d",&n); for(int i=1;i<n;i++){ int a,b; scanf("%d%d",&a,&b); Add(a,b); } dfs(1,0); printf("%d\n",min(A[1],B[1])); return 0;}
阅读全文
0 0
- 洛谷P2899 [USACO08JAN]手机网络Cell Phone Network
- poj3659[USACO2008,Jan]Cell Phone Network手机网络
- BSOJ: 1708 【USACO 2008 January Gold】Cell Phone Network手机网络
- POJ3659 Cell Phone Network
- POJ 3659 Cell Phone Network
- POJ-3659-Cell Phone Network
- POJ 3659 Cell Phone Network
- POJ 3659 Cell Phone Network
- POJ 3659——Cell Phone Network
- [树形DP] poj 3659 Cell Phone Network
- poj 3659 Cell Phone Network 贪心
- POJ 3659 Cell Phone Network(贪心)
- poj3659 Cell Phone Network(树形dp)
- Android network 手机网络
- POJ3659 Cell Phone Network【最小支配集】【贪心】
- poj3659 Cell Phone Network(最小支配集-树形dp)
- POJ 3659 Cell Phone Network(树形DP)
- 【POJ3659】Cell Phone Network【树上最小点支配】【TreeDP】
- BootStrap(三)模态框
- 第三天上班学习内容
- unity shader中的矩阵变换知识
- 【Java学习笔记】实现简单的宠物商店管理
- 数据结构第七周项目一-建立链队算法库
- 洛谷P2899 [USACO08JAN]手机网络Cell Phone Network
- C++笔记——拷贝构造函数2
- 疯狂讲义随笔——使用二次曲线quadraticCurveTo()画花朵
- Spring
- 《利用python进行数据分析》ch02续
- 模拟的操作系统nachos解读
- java HMACSHA1与php hash_hmac 函数
- 安装HBase出现的问题
- C++设计模式 -> 行为型 -> 观察者模式(Observer Pattern)