繁华模拟赛 David与Vincent的博弈游戏



#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的博弈游戏的更多相关文章
- 繁华模拟赛 David与阶乘
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...
- David与Vincent的博弈游戏[树型DP]
\(\mathcal{Description}\) \(\mathcal{Solution}\) 根据题意,我们知道 根节点深度为1,深度为 奇数 的节点由\(David\)移动,我们称为\(D\)点 ...
- 繁华模拟赛 Vincent的城堡
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- 繁华模拟赛 Vicent与游戏
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...
- [繁华模拟赛]Evensgn 剪树枝
Evensgn 剪树枝 题目 繁华中学有一棵苹果树.苹果树有 n 个节点(也就是苹果),n − 1 条边(也就 是树枝).调皮的 Evensgn 爬到苹果树上.他发现这棵苹果树上的苹果有两种:一 种是 ...
- 繁华模拟赛day8 牛栏
/* 标称并没有用到题解中提到的那种奇妙的性质,我们可以证明,正常从1开始走的话,需要T次,如何使这个次数减小?题解中提到一个办法,有一步小于n/t,我们考虑这一步,如果把它匀到左右两步中,则可以减小 ...
- 繁华模拟赛day8 字典序
/* 这个题要我们求一个字典序,字符串给出的顺序,会对字母的字典序前后相对顺序进行限定,如何用来表示这种限定,我们注意到这种一个之后接着一个,只有先输出他前面的才能输出他,很明显就是拓扑排序,最小方案 ...
- 繁华模拟赛day8 科技树
/* 贪心,很明显是越容易升级的越先升级 */ #include<iostream> #include<cstdio> #include<string> #incl ...
- 繁华模拟赛 Vicent坐电梯
/*n<=5000这样就不能用O(n)的转移了,而是要用O(1)的转移.注意我们每次的转移都来自一个连续的区间,而且我们是求和区间求和?前缀和!令sum[step][i]表示f[ste ...
随机推荐
- iOS - 语音云通讯
iOS SDK 2.0 语音及图片消息详解本文档将详细介绍融云的语音及图片消息接口功能及使用说明.阅读本文前,我们假设您已经阅读了融云 iOS 开发指南,并掌握融云 SDK 的基本用法. 语音消息用来 ...
- poj1067-取石子游戏-wythoff博弈
打表找规律失败,搜了一下原来是wythoff博弈 /*------------------------------------------------------------------------- ...
- 零散知识记录-一个MQ问题
[背景]我有一项零散工作:维护大部门的一台测试公用MQ服务器.当大部分MQ被建立起来,编写了维护手册,大家都按照规程来后,就基本上没有再动过它了.周五有同学跟我反映登录不进去了,周日花了1个小时来解决 ...
- Asp.Net MVC 合并js或css请求
Step1:BundleConfig中注册 bundles.Add(new ScriptBundle("~/isValid").Include( "~/Scripts/ ...
- node设置cookie
// 获得客户端的Cookie var Cookies = {}; req.headers.cookie && req.headers.cookie.split(';' ...
- VS2010版快捷键
VS2010版快捷键 Ctrl+E,D ----格式化全部代码 Ctrl+E,F ----格式化选中的代码 CTRL + SHIFT + B生成解决方案 CTRL + F7 生成编译 CTRL + O ...
- 每天一个linux命令(29):date命令
在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用到时间的运算,熟练运用date命令来表示自己想要表示的时间,肯定可以给自己的工作带来诸多方便. 1.命令格式: date [参数 ...
- eclipse&android的环境搭建
这次我选择使用Android来完成这次软件工程实践,不过配置eclipse和android环境真是个麻烦事. 因为之前有用过eclipse,对其比较熟悉,于是就放弃了android studio这个工 ...
- [转]SQL注入攻防入门详解
原文地址:http://www.cnblogs.com/heyuquan/archive/2012/10/31/2748577.html =============安全性篇目录============ ...
- hdu1828 线段树+离散化+扫描线
添加lb[],rb[]数组,来标记竖边.添加num,来计算竖边的个数,因为计算周长的时候,未覆盖的竖边都要加. #include<stdio.h> #include<stdlib.h ...