#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
struct edge{
int to;
int nxt;
};
int n,g[maxn],dep[maxn],dpd[maxn],dpv[maxn];
int head[maxn],cnt;
edge e[maxn];
inline void add_edge(int u,int v){
cnt++;
e[cnt].to = v;
e[cnt].nxt = head[u];
head[u] = cnt;
}
void input(){
cin>>n;
int u,v;
for(int i = ;i < n;i++){
scanf("%d%d",&u,&v);
add_edge(u,v);
}
}
void dfs(bool dep,int x){
if(!head[x]){
dpd[x] = dpv[x] = g[x] = ;
return;
}
for(int i = head[x];i;i = e[i].nxt){
dfs(!dep,e[i].to);
g[x] += g[e[i].to];
}
dpv[x] = dpd[x] = ;
if(dep){
int sum = ;
for(int i = head[x];i;i = e[i].nxt){
sum += dpv[e[i].to] - ;
dpd[x] = max(dpd[x],g[x]-g[e[i].to]+dpd[e[i].to]);
}
dpv[x] = max(dpv[x],sum+);
}else{
int sum = ;
for(int i = head[x];i;i = e[i].nxt){
sum += dpd[e[i].to] - ;
dpv[x] = max(dpv[x],g[x]-g[e[i].to]+dpv[e[i].to]);
}
dpd[x] = max(dpd[x],sum+);
}
}
int main(){
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
input();
dfs(true,);
cout<<dpd[]<<" "<<g[] - dpv[] + ;
return ;
} #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define N 200005
#define fi first
#define se second
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int dp[N],fa[N],lf[N],m;
vector<int> G[N];
void dfs1(int x,int d)
{
int v,i;
if(d==) dp[x]=INF;
else dp[x]=;
for(i=;i<G[x].size();i++)
{
v=G[x][i];
if(fa[x]!=v)
{
lf[x]=;
fa[v]=x;
dfs1(v,d^);
if(d==)
dp[x]=min(dp[x],dp[v]);
else dp[x]+=dp[v];
}
}
if(!lf[x])
dp[x]=,m++;
} void dfs2(int x,int d)
{
int v,i;
if(d==) dp[x]=;
else dp[x]=INF;
for(i=;i<G[x].size();i++)
{
v=G[x][i];
if(fa[x]!=v)
{
lf[x]=;
fa[v]=x;
dfs2(v,d^);
if(d==)
dp[x]+=dp[v];
else dp[x]=min(dp[x],dp[v]);
}
}
if(!lf[x])
dp[x]=;
//debug(x);
//debug(dp[x]);
} int main()
{
int n,i,a,b;
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
cin>>n;
for(i=;i<n;i++)
{
scanf("%d%d",&a,&b);
G[a].push_back(b);
//G[b].push_back(a);
}
dfs1(,);
cout<<m-dp[]+<<' ';
dfs2(,);
cout<<dp[]<<endl;
return ;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);

繁华模拟赛 David与Vincent的博弈游戏的更多相关文章

  1. 繁华模拟赛 David与阶乘

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...

  2. David与Vincent的博弈游戏[树型DP]

    \(\mathcal{Description}\) \(\mathcal{Solution}\) 根据题意,我们知道 根节点深度为1,深度为 奇数 的节点由\(David\)移动,我们称为\(D\)点 ...

  3. 繁华模拟赛 Vincent的城堡

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  4. 繁华模拟赛 Vicent与游戏

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...

  5. [繁华模拟赛]Evensgn 剪树枝

    Evensgn 剪树枝 题目 繁华中学有一棵苹果树.苹果树有 n 个节点(也就是苹果),n − 1 条边(也就 是树枝).调皮的 Evensgn 爬到苹果树上.他发现这棵苹果树上的苹果有两种:一 种是 ...

  6. 繁华模拟赛day8 牛栏

    /* 标称并没有用到题解中提到的那种奇妙的性质,我们可以证明,正常从1开始走的话,需要T次,如何使这个次数减小?题解中提到一个办法,有一步小于n/t,我们考虑这一步,如果把它匀到左右两步中,则可以减小 ...

  7. 繁华模拟赛day8 字典序

    /* 这个题要我们求一个字典序,字符串给出的顺序,会对字母的字典序前后相对顺序进行限定,如何用来表示这种限定,我们注意到这种一个之后接着一个,只有先输出他前面的才能输出他,很明显就是拓扑排序,最小方案 ...

  8. 繁华模拟赛day8 科技树

    /* 贪心,很明显是越容易升级的越先升级 */ #include<iostream> #include<cstdio> #include<string> #incl ...

  9. 繁华模拟赛 Vicent坐电梯

    /*n<=5000­这样就不能用O(n)的转移了,而是要用O(1)的转移.­注意我们每次的转移都来自一个连续的区间,而且我们是求和­区间求和?­前缀和!­令sum[step][i]表示f[ste ...

随机推荐

  1. Jquery操作select,radio,input,p之类

    select的操作 变化后触发操作 $("#txtaddprojecturl").change(function(){ $("#addprojectname") ...

  2. 关于UITextView / String的尺寸

    关于UITextView以及String的尺寸动态获取 iOS7开始,UITextView设置text后不会立即反映到contentSize属性,而是在父容器layoutSubviews时进行cont ...

  3. groot 引入外部模板

    index7.html <html><head> <title>groots引入外部模板van</title> <script src=" ...

  4. 几种Boost算法的比较(Discrete AdaBoost, Real AdaBoost, LogitBoost, Gentle Adaboost)

    关于boost算法 boost算法是基于PAC学习理论(probably approximately correct)而建立的一套集成学习算法(ensemble learning).其根本思想在于通过 ...

  5. 第十章:Javascript子集和扩展

    本章讨论javascript的集和超集,其中子集的定义大部分处于安全考虑.只有使用这门语言的一个安全的子集编写脚本,才能让代码执行的更安全.更稳定.ECMScript3标准是1999年版本的,10年后 ...

  6. beta版本贡献率

    队名:攻城小分队 031302410 郭怡锋 : 占比:50% 031302411 洪大钊: 占比:30% 031302206 陈振贵: 占比:10% 031302416 黄伟祥: 占比:10%

  7. java多线程-Exchanger

    简介: 可以在对中对元素进行配对和交换的线程的同步点.每个线程将条目上的某个方法呈现给exchange方法,与伙伴线程进行匹配,并且在返回时接收其伙伴的对象.Exchanger 可能被视为Synchr ...

  8. 图解Android - Looper, Handler 和 MessageQueue

    Looper, Handler 和 MessageQueue 是Android 的异步消息处理机制

  9. 【ZOJ 3870】 Team Formation

    题意 n个数,找出有几对a.b 符合 a ^ b > max(a,b) .^表示异或号 分析 对于数a,如果它的二进制是: 1 0 1  0 0 1,那么和它 ^ 后 能比他大的数就是: 0 1 ...

  10. hdu 1575 矩阵快速幂模板

    #include "iostream" #include "vector" #include "cstring" using namespa ...