#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. php利用递归函数实现无限级分类

    相信很多学php的很多小伙伴都会尝试做一个网上商城作为提升自己技术的一种途径.各种对商品分类,商品名之类的操作应该是得心应手,那么就可以尝试下无限级分类列表的制作了. 什么是无限级分类? 无限级分类是 ...

  2. 360wifi 在 windows server 2008 / 2003 的使用方法

    1. 安装驱动 在地址栏输入:Control Panel\System and Security\Administrative Tools , 然后找到Server Manager 打开 Server ...

  3. linux网络命令

    关键字 write wall last lastlog traceroute netstat mount 1.write 该命令可以给所有在线用户发送消息 示例: 接受消息用户:按回车可以退出 2.w ...

  4. 第三章:javascript: 列表

    在日常生活中,人们经常使用列表:待办事项列表,购物清单,十佳榜单,最后十名榜单等.计算机也在使用列表,尤其是列表中元素保存的是太多时.当不需要一个很长的序列中查找元素,或对其进行排序时,列表显得尤为有 ...

  5. go语言指针符号的*和&

    先看一段代码 先放一段代码,人工运行一下,看看自己能做对几题? package main import "fmt" func main() { var a int = 1 var ...

  6. 使用Git进行代码管理心得

    关于使用Git for Windows来clone和上传项目 首先到Git for Windows的官网下载并安装 在本地用来保存clone文件的文件夹右键,选择Git Bash Here: 在打开的 ...

  7. ORACLE建表练习

    1,学生表 -- Create table create table T_HQ_XS ( xueh ) not null, xingm ) not null, xingb ) ', nianl NUM ...

  8. hdu1281 二分匹配

    求重要的点.那就可以通过枚举来找:先做一次最大匹配,求出匹配数.然后逐一枚举这些点.如果匹配数改变,那就是重要点: #include<stdio.h> #include<string ...

  9. Java基础-设计模式之-代理模式Proxy

    代理模式是对象的结构模式.代理模式给某一个对象提供一个代理对象,并由代理对象控制对原对象的引用. 代理模式是常用的Java 设计模式,它的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理 ...

  10. Nuget的使用命令

    Nuget的命令行操作都是在程序包管理器控制台下进行的:结构如图: