#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. iOS中几种定时器

    在软件开发过程中,我们常常需要在某个时间后执行某个方法,或者是按照某个周期一直执行某个方法.在这个时候,我们就需要用到定时器. iOS中定时器NSTimer的使用   1.初始化 + (NSTimer ...

  2. Opencv step by step - 阈值化

    Opencv里面的阈值化做起来比较简单,只需要一个函数即可: /* Applies fixed-level threshold to grayscale image. This is a basic ...

  3. 最简单的 Web Service 入门 (看了包会)

    原理:WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于SOAP协议的网络应用间的交互. 作用:主要 ...

  4. C# 使用XML序列化对象(二)

    在C# 使用XML序列化对象(一)中描述了使用XML序列化对象的最简单的实现. 现在我们来看看稍微复杂一点的情况: 现有两个类:A和B,B是A的派生类,如下所示: public class A { p ...

  5. win8.1右键新建菜单添加新建php文件

    最近在学习php没使用IDE,一直使用编辑器,但每次新建文件都要手动该扩展名比较麻烦.于是想着能不能在右键新建菜单直接新建php文件.于是开始百度... 步骤一:win+R打开运行(管理员身份运行) ...

  6. python 类型之 set

    python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...

  7. 阿里云搭建基于PPTP的VPN(Windows Server 2008)

    由于阿里云在网络上分为两张网卡,一张内网,另一张是外网,所以在搭建PPTP的VPN时需要特殊处理. 实现步骤: 通过以上配置即可拨号成功 下面是通过NFS策略进行控制访问  完成后,即可拨号上网. 下 ...

  8. Vijos1459 车展 (treap)

    描述 遥控车是在是太漂亮了,韵韵的好朋友都想来参观,所以游乐园决定举办m次车展.车库里共有n辆车,从左到右依次编号为1,2,…,n,每辆车都有一个展台.刚开始每个展台都有一个唯一的高度h[i].主管已 ...

  9. Memory Allocation API In Linux Kernel && Linux Userspace、kmalloc vmalloc Difference、Kernel Large Section Memory Allocation

    目录 . 内核态(ring0)内存申请和用户态(ring3)内存申请 . 内核态(ring0)内存申请:kmalloc/kfree.vmalloc/vfree . 用户态(ring3)内存申请:mal ...

  10. JAVA中的数组是对象吗?

    public class Main{ public static void main(String[] args) { int a[]={1,9}; //Object obj=new int[10]; ...