#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. 崩溃日志记录工具Crashlytics

    http://try.crashlytics.com 申请账号,通常一两天 设置工程 后期更新,个人感觉使用这个很麻烦

  2. 开发一个简单实用的android紧急求助软件

    之前女朋友一个人住,不怎么放心,想找一个紧急求助的软件,万一有什么突发情况,可以立即知道.用金山手机卫士的手机定位功能可以知道对方的位置状态,但不能主动发送求助信息,在网上了很多的APK,都是鸡肋功能 ...

  3. ubuntu apt-get修改源地址

    亲测搜狐可用,其他备用 1.修改源地址:cp /etc/apt/sources.list /etc/apt/sources.list.bakvim /etc/apt/sources.list 修改之后 ...

  4. 给 Xamarin.Form For Windows Phone APP 加个漂亮的 "头"

    Windows Phone 是那个1%, 我也是那个1%, 不喜勿喷.WP 向来给 android / ios 的粉们一个最直观的印象: 丑.其实"丑"这个东西会一直下去,而且是个 ...

  5. 第二章 Js函数

      函数的定义二种定义 ①function myfunc () { console("hello"); }; ②var myfunc = function () { console ...

  6. session和cookie的前后的操作

    1. // sign outexports.signout = function (req, res, next) { req.session.destroy(); res.clearCookie(c ...

  7. Grovvy Step byStep Examples

    def LIMIT=10 def count=1 println 'start' while(count<=LIMIT){ println "count:${count}" ...

  8. HOW TO REMOTELY DEBUG APPLICATION RUNNING ON TOMCAT FROM WITHIN INTELLIJ IDEA

    This post would look into how to tackle and debug issues in scenarios where they only occur in produ ...

  9. 使用TransactionScopeOption 管理事务流

    可通过调用一个方法来嵌套事务范围,该方法在使用其自己范围的方法中使用 TransactionScope,下面示例中的 RootMethod 方法就是前者这样的方法. void RootMethod() ...

  10. HTML5 文件操作API

    简介 我常常想,如果网络应用能够读取和写入文件与目录,将会非常方便.从离线转移到在线后,应用变得更加复杂,而文件系统方面的API的缺乏也一直阻碍着网络前进.存储二进制数据或与其进行交互不应局限于桌面. ...