Codeforces Round #300 E - Demiurges Play Again
感觉这种类型的dp以前没遇到过。。。 不是很好想。。
dp[u] 表示的是以u为子树进行游戏得到的值是第几大的。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, sum[N], dp[N], f[N], dp2[N];
vector<int> edge[N]; void dfs(int u, int fa) {
for(int v : edge[u]) {
if(v == fa) continue;
f[u] = true;
dfs(v, u);
sum[u] += sum[v];
}
sum[u] += !f[u];
} void dfs2(int u, int fa, int depth) {
if(!f[u]) {
dp[u] = ;
dp2[u] = ;
return;
}
if(depth & ) {
dp2[u] = inf;
for(int v : edge[u]) {
if(v == fa) continue;
dfs2(v, u, depth + );
dp[u] += dp[v];
dp2[u] = min(dp2[u], dp2[v]);
}
} else {
dp[u] = inf;
for(int v : edge[u]) {
if(v == fa) continue;
dfs2(v, u, depth + );
dp[u] = min(dp[u], dp[v]);
dp2[u] += dp2[v];
}
}
} int main() {
scanf("%d", &n);
for(int i = ; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
edge[u].push_back(v);
edge[v].push_back(u);
}
dfs(, );
dfs2(, , );
printf("%d %d\n", sum[] - dp[] + , dp2[]);
return ;
} /*
5
1 5 4 3 2
*/
Codeforces Round #300 E - Demiurges Play Again的更多相关文章
- 贪心 Codeforces Round #300 A Cutting Banner
题目传送门 /* 贪心水题:首先,最少的个数为n最大的一位数字mx,因为需要用1累加得到mx, 接下来mx次循环,若是0,输出0:若是1,输出1,s[j]--: 注意:之前的0的要忽略 */ #inc ...
- 水题 Codeforces Round #300 A Cutting Banner
题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...
- Codeforces Round #300 解题报告
呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...
- Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)
A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #300(Div. 2)-538A.str.substr 538B.不会 538C.不会 。。。
A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #300 A. Cutting Banner 水题
A. Cutting Banner Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pro ...
- Codeforces Round #300 D. Weird Chess 水题
D. Weird Chess Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/proble ...
- Codeforces Round #300 C. Tourist's Notes 水题
C. Tourist's Notes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pr ...
- Codeforces Round #300 B. Quasi Binary 水题
B. Quasi Binary Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/probl ...
随机推荐
- xshell输入奇怪,空格间距变大
https://www.macx.cn/thread-2018939-1-1.html 按一下shift+空格就行了 全角/半角转换的快捷键... dd
- 出现错误日志:The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
tomcat6出现错误日志: 信息: The APR based Apache Tomcat Native library which allows optimal performance in ...
- Bootstrap3和Bootsrap4的区别
Bootstrap3和Bootstap4的区别 1.Bootsrap4 css文件减少了40%以上 2.Bootsrap4已经不支持IE8以及IOS 6的支持 3.多了些类好组件
- C语言 结构体传值与传址分析
/********************************************************************** * 版权所有 (C)2017, Wang maochun ...
- 关于java 获取 html select标签 下拉框 option 文本内容 隐藏域
在HTML中从多选下拉框中提取已选中选项的文本内容到后台,被这个问题难倒了. demo.jsp文件 <select id="selecttype" name"typ ...
- HDU 5145 分块 莫队
给定n个数,q个询问[l,r]区间,每次询问该区间的全排列多少种. 数值都是30000规模 首先考虑计算全排列,由于有同种元素存在,相当于每次在len=r-l+1长度的空格随意放入某种元素即$\bin ...
- Codeforces 450B div.2 Jzzhu and Sequences 矩阵快速幂or规律
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- 在asp.net 中生成PDF的方法
近期要用asp.net 2.0生成PDF,看了下书,查了下资料,发现可以有组件帮得上忙,可以下载itextsharp(https://sourceforge.net/projects/itextsha ...
- ES6核心,值得驻足花一天时间来学习
1.let 和 const 命令 在es5时,只有两种变量声明,var 和function.在es6中新增了四种let和const,以及另外两种声明import和class. 我们先讲解let和con ...
- styled-components真的好吗?
最近在学习react,然后遇到react中css该怎么写这个问题,上知乎上看了好多大牛都说styled-components好用是大势所趋. 但我自己用了感觉体验却很差,我在这里说说我为啥觉得styl ...