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 ...
随机推荐
- Redis使用的相关问题
Redis用那些数据结构? 字符串类型String 字典Hash 列表List 集合Set 有序集合SortedSet HyperLogLog.Geo.Pub/Sub Redis Module.Blo ...
- php array数组(第二部分)
array_fill() 用给定的键值填充数组 参数 index 必须.规定返回数组的起始索引. 参数 number 必须.规定填充的元素的数量,其值必须大于0. 参数 value 必须.规定用于填充 ...
- Git 分支管理 创建与合并分支
分支在实际中有什么用呢? 假设你准备开发一个新功能,但是需要两周才能完成,第一周你写了50%的代码,如果立刻提交,由于代码还没写完,不完整的代码库会导致别人不能干活了. 如果等代码全部写完再一次提交, ...
- 动态生成navmeshi-进击的新版NavMesh系统:看我飞檐走壁
http://forum.china.unity3d.com/thread-25421-1-1.html0x00 前言 unity5.6作为Unity5最后的一个版本,的确起到了一个承上启下的作用.除 ...
- 使用Unity容器实现属性注入
简介 Unity :是微软用C#实现的轻量级,可扩展的依赖注入容器. 控制反转:(Inversion of Control,缩写为IoC),是用来消减程序之间的耦合问题,把程序中上层对下层依赖,转移到 ...
- pytest框架(三)
pytharm运行三种方式 代码示例: # coding=utf-8 import pytest class TestClass: def test_one(self): x = "this ...
- Python学习笔记(随机数)
random模块的作用是产生随机数. import random num = random.randint(1,100) random.randint(a, b)可以生成一个a到b间的随机整数,包括a ...
- 5.格式化输出f
16.1 不区分大小写 num = input('>>>') s = F'python{num}' print(s) 16.2 可以加入表达式 s1='alex' s2=f'我的名字 ...
- 页面出现滚动条时,body里面的内容不能自动居中?
弹窗后允许页面滚动 这种方式通常使用 position: absolute; ,可以看看我做的这个 Demo.主要用来应对弹窗内容很大很多的情况,超过了屏幕的宽高需要产生滚动条来方便浏览者查看.有一些 ...
- AtCoder Regular Contest 082 ABCD
A #include<bits/stdc++.h> using namespace std; ]; int n,m; int main(){ cin>>n>>m; ...