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 ...
随机推荐
- web项目中解决post乱码和get乱码的方法
前提复习编码问题产生的原因: 1. 什么是URL编码. URL编码是一种浏览器用来打包表单输入的格式,浏览器从表单中获取所有的name和其对应的value,将他们以name/value编码方式作为U ...
- Python --Redis Hash操作
一.Redis Hash操作 Redis 数据库hash数据类型是一个string类型的key和value的映射表,适用于存储对象.Redis 中每个 hash 可以存储 232 - 1 键值对(40 ...
- VS工程使用Git时的过滤文件
1.解决方案必须保留的文件sln和suo,需要过滤的文件为sdfVisual Studio.NET采用两种文件类型(.sln和.suo)来存储特定于解决方案的设置,它们总称为解决方案文件.为解决方案资 ...
- 《Apache HttpClient 4.3开发指南》
转载自:http://blog.csdn.net/chszs/article/details/16854747 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chs ...
- Centos 修改limits.conf open files后不生效的解决办法
线上几台APACHE服务器报过三.四次open files的问题,导致服务不可用,执行ulimit -n 查看后,发现是默认的1024,找到原因所在了,就去修改下/etc/security/limit ...
- [Thu Summer Camp 2015]解密运算
4104: [Thu Summer Camp 2015]解密运算 Time Limit: 10 Sec Memory Limit: 512 MB Description 对于一个长度为N的字符串,我 ...
- Spring容器简介
Spring 是面向 Bean 的编程(BOP,Bean Oriented Programming),提供了 IOC 容器通过配置文件或者注解的方式来管理对象之间的依赖关系. 控制反转模式(也称作依赖 ...
- [linux]ubuntu在线安装mysql
1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client 3. sudo apt-get install li ...
- 【leetcode 简单】 第五十三题 删除重复的电子邮箱
编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个. +----+------------------+ | Id | Email | +-- ...
- 关于Re模块的一些基础知识(另附一段批量抓代理ip的代码)
1.常用匹配规则 . 表示任意字符[0-9] 用来匹配一个指定的字符类别[^5]表示除了5之外的其他字符,^不在字符串的开头,则表示它本身.* 对于前一个字符重复0到无穷次+ 对于前一个字符重复1到无 ...