Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)
dfs一遍,维护当前连续遇到的喵的数量,然后剪枝,每个统计孩子数量判断是不是叶子结点。
#include<bits/stdc++.h>
using namespace std; const int maxn = 2e5+;
int a[maxn];
int head[maxn],nxt[maxn<<],to[maxn<<],ect; inline void addEdge(int u,int v)
{
to[ect] = v;
nxt[ect] = head[u];
head[u] = ect++;
} int ct[maxn],m,cnt;
void dfs(int u,int f)
{
if(a[u]) ct[u] = ct[f]+;
if(ct[u]>m) return;
int ch = ;
for(int i = head[u]; ~i ; i = nxt[i]){
int v = to[i];
if(v == f) continue;
ch++;
dfs(v,u);
}
if(!ch) { cnt++; }
} //#define LOCAL int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
memset(head,-,sizeof(head));
int n; scanf("%d%d",&n,&m);
for(int i = ; i <= n; i++) scanf("%d",a+i);
for(int i = ; i < n; i++){
int u,v; scanf("%d%d",&u,&v);
addEdge(u,v); addEdge(v,u);
}
dfs(,);
printf("%d",cnt);
return ;
}
Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)的更多相关文章
- Codeforces Round #321 (Div. 2) C. Kefa and Park dfs
C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...
- Codeforces Round #321 (Div. 2) E. Kefa and Watch 线段树hash
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company 二分
B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/pr ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题
A. Kefa and First Steps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/58 ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp
题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...
- codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)
题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)
http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #321 (Div. 2) E Kefa and Watch (线段树维护Hash)
E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- Thinkphp3.2 备份数据库和还原数据的方法
其实Thinkphp框架并没有自带备份数据库的功能,但是细心的朋友可能会发现Thinkphp的一套内容管理系统oneThink是有备份数据库和还原数据的功能的. 所以今天我就来聊一聊,oneThink ...
- UVa 11404 Palindromic Subsequence (LCS)
题意:给定一个字符串,问删除一些字符,使得它成为一个最长回访串,如果有多个,输出字典序最小的那个. 析: 我们可以把原字符串反转,然后求两个串的LCS,就得到最长回文串,不过要注意一些细节. 代码如下 ...
- win7 卸载ie10+ 重新安装ie8
烦恼: erp系统不支持高版本ie10+ 项目开发测试需要安装了高版本ie 项目结束,为了方便使用erp,决定卸载ie11,重新安装ie8 解决方法: 1.win+R打开运行命令,键入appwiz.c ...
- 一、初识mybatis
orm框架 1.配置文件(配置别名.mapper xml文件.数据库连接.事务) 2.创建SqlSessionFactory,创建SqlSession 3.创建model,创建Mapper xml文件 ...
- linux文件重命名
rename 命令用字符串替换的方式批量改变文件名. 语法 rename(参数) 参数 原字符串:将文件名需要替换的字符串: 目标字符串:将文件名中含有的原字符替换成目标字符串: 文件:指定要改变文件 ...
- 洛谷P2652 同花顺
P2652 同花顺 题目背景 所谓同花顺,就是指一些扑克牌,它们花色相同,并且数字连续. 题目描述 现在我手里有n张扑克牌,但它们可能并不能凑成同花顺.我现在想知道,最少更换其中的多少张牌,我能让这 ...
- Nacos深入浅出(四)
private void executeAsyncInvoke() { while (!queue.isEmpty()) { NotifySingleTask task = queue.poll(); ...
- C8051开发环境
1 keilC51 2 Silicon Laboratories C8051Fxxx uVision Driver_4 C:\Keil9 3 Silicon Laboratories Configu ...
- (转)COBBLER无人值守安装
COBBLER无人值守安装 说在最前面的话 在看Cobbler之前请大家先看一下Kickstart无人值守安装,了解一下Cobbler的实现原理.但是Cobbler是独立的,不需要先安装Kicksta ...
- Spark Mllib里的向量标签概念、构成(图文详解)
不多说,直接上干货! Labeled point: 向量标签 向量标签用于对Spark Mllib中机器学习算法的不同值做标记. 例如分类问题中,可以将不同的数据集分成若干份,以整数0.1.2,... ...