原题链接:

题意:

给你一棵有根树,某些节点的权值是1,其他的是0,问你从根到叶子节点的权值和不超过m的路径有多少条。

题解:

直接dfs一下就好了。

代码:

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#define MAX_N 100005
using namespace std; vector<int> G[MAX_N];
int n,m;
bool cat[MAX_N]; int ans=; void dfs(int u,int p,int c) {
if (c > m)return;
bool update = false;
for (int i = ; i < G[u].size(); i++) {
int v = G[u][i];
if (v == p)continue;
update = true;
dfs(v, u, cat[v] * (c + cat[v]));
}
if (!update)ans++;
} int main(){
cin.sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=n;i++)
cin>>cat[i];
for(int i=;i<n-;i++){
int x,y;
cin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(,,cat[]);
cout<<ans<<endl;
return ;
}

Codeforces Round #321 (Div. 2) Kefa and Park 深搜的更多相关文章

  1. Codeforces Round #321 (Div. 2) Kefa and Dishes 状压+spfa

    原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令 ...

  2. Codeforces Round #321 (Div. 2) Kefa and Company 二分

    原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大 ...

  3. Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟

    原题连接:http://codeforces.com/contest/580/problem/A 题意: 给你一个序列,问你最长不降子串是多长? 题解: 直接模拟就好了 代码: #include< ...

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

  5. Codeforces Round #321 (Div. 2) C dfs处理(双向边叶子节点的判断)

    C. Kefa and Park time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. Codeforces Round #321 (Div. 2) A, B, C, D, E

    580A. Kefa and First Steps 题目链接: A. Kefa and First Steps 题意描述: 给出一个序列,求最长不降连续子序列多长? 解题思路: 水题,签到 代码: ...

  7. Codeforces Round #321 (Div. 2)

    水 A - Kefa and First Steps /************************************************ * Author :Running_Time ...

  8. 「日常训练」Kefa and Park(Codeforces Round #321 Div. 2 C)

    题意与分析(CodeForces 580C) 给你一棵树,然后每个叶子节点会有一家餐馆:你讨厌猫(waht?怎么会有人讨厌猫),就不会走有连续超过m个节点有猫的路.然后问你最多去几家饭店. 这题我写的 ...

  9. Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)

    dfs一遍,维护当前连续遇到的喵的数量,然后剪枝,每个统计孩子数量判断是不是叶子结点. #include<bits/stdc++.h> using namespace std; ; int ...

随机推荐

  1. 实践自己的WebSite______流水

    尝试从头至尾搭建一个MVC的网站,主要以流水的方式进行进度和记录,而不讨论技术的部分. 1,在Controller下创建两个文件夹,分别为sys和Business,分别对应于系统功能和业务逻辑.比如登 ...

  2. Python使用asyncio+aiohttp异步爬取猫眼电影专业版

    asyncio是从pytohn3.4开始添加到标准库中的一个强大的异步并发库,可以很好地解决python中高并发的问题,入门学习可以参考官方文档 并发访问能极大的提高爬虫的性能,但是requests访 ...

  3. 带有命名空间的xml解析,C#

    前一段时间做花旗的接口,返回的xml格式是带有命名空间的,可是难倒了我,找了好久才找到解决办法,给大家分享下,少走弯路. 1,直接进入正题,先看一段带有命名空间的xml,这段xml大概的意思是,前面是 ...

  4. [转]mysql Access denied for user 'root'@'localhost' 问题的解决方法

    解决方案如下: # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &a ...

  5. php将数组写入到文件的三种方法

    php将数组原样写入或保存到文件有三种方法可以实现, 第一种方法是使用serialize, 第二种方法是使用print_r, 第三种方法是使用var_export, 本文章向大家介绍这三种方法是如何将 ...

  6. 微信小程序开发 -- 获取当前页面路径

    Page.prototype就是this: 你在任何一个Page里面都可以使用route字段和setData()函数: 示例代码: /** * 生命周期函数--监听页面加载 */ onLoad: fu ...

  7. 【SDOJ 3741】 【poj2528】 Mayor's posters

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  8. 设计模式之单例模式 Singleton实现

    饿汉式 饿汉式单例模式,static变量会在类装载时初始化,此时也不会涉及多个线程对象访问该对象的问题.虚拟机保证只会装载一次该类,肯定不会发生并发访问的问题, 因此可以省略synchronized关 ...

  9. TOJ1017: Tour Guide

      描述 You are working as a guide on a tour bus for retired people, and today you have taken your regu ...

  10. [译] Pandas中根据列的值选取多行数据

    # 选取等于某些值的行记录 用 == df.loc[df['column_name'] == some_value] # 选取某列是否是某一类型的数值 用 isin df.loc[df['column ...