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(深搜)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)

    http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. js.alert(重写)

    function dialogFn(Msg, btnOkCallBack, btnCancelCallBack) { $("body").append('<div id=&q ...

  2. MS SQL PIVOT数据透视表

    以前曾经做过练习<T-SQL PIVOT 行列转换>https://www.cnblogs.com/insus/archive/2011/03/05/1971446.html 今天把拿出来 ...

  3. deb包制作

    制作deb包 方法一:checkinstall checkinstall的原理就是将make install的内容放到一个临时目录然后打包,只要能执行make install就能创建deb包,如果代码 ...

  4. maven - 初识

    一.Maven是什么? Maven官网的描述:Apache Maven is a software project management and comprehension tool. Based o ...

  5. maven 参考

    系列文章,通俗易懂,可以看看 http://www.cnblogs.com/AlanLee/category/918828.html

  6. Maven项目编译版本的问题和Spring中没有导入核心包

    idea中maven项目的编译: 方案1:maven的settings.xml中指定全局默认编译版本 <profile> <id>jdk-1.8</id> < ...

  7. 黑马MyBatisday2 MyBatis Dao层实现 接口代理实现&传统实现 动态SQL和SQL抽取 自定义类型处理 分页插件PageHelper

    package com.itheima.mapper; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelp ...

  8. 数据库性能分析 慢查询 profile工具

  9. mybatis pageHelper 分页插件使用

    转载大神 https://blog.csdn.net/qq_33624284/article/details/72828977 把插件jar包导入项目(具体上篇有介绍http://blog.csdn. ...

  10. Java8中的新特性Optional

    Optional 类是一个可以为null的容器对象.如果值存在则isPresent()方法会返回true,调用get()方法会返回该对象.Optional 是个容器:它可以保存类型T的值,或者仅仅保存 ...