codeforces 580C Kefa and Park
来源:互联网 发布:手机送货单软件 编辑:程序博客网 时间:2024/06/06 10:51
题目大意:一个人要去餐馆,每个叶子节点是一个餐馆,标记为1的点是有猫的,如果连续出现超过n只猫就不能走,问你最多能去几个餐馆
点有点多,不能用二维数组去存,然后用深搜
#include<iostream>#include<vector>using namespace std;#define INPUT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)const int maxn=1e5+7;vector<int> vec[maxn];int num[maxn];int ans;int n,m;void dfs(int u,int cnt,int flag){for(int i=0;i<vec[u].size();i++){int v=vec[u][i];if(v==flag) continue;if(num[v]==0){if(vec[v].size()==1) ans++;dfs(v,0,u);}else if(cnt+1<=m){if(vec[v].size()==1) ans++;dfs(v,cnt+num[v],u);}}}int main(){INPUT;cin>>n>>m;for(int i=1;i<=n;i++){cin>>num[i];}for(int i=0;i<n-1;i++){int a,b;cin>>a>>b;vec[a].push_back(b);vec[b].push_back(a);}dfs(1,num[1],-1);cout<<ans<<endl;}
阅读全文
0 0
- codeforces-580C-Kefa and Park【dfs】
- Codeforces 580C Kefa and Park
- Codeforces 580C Kefa and Park 题解
- codeforces 580C Kefa and Park
- Codeforces Round #321 (Div. 2) 580C - Kefa and Park
- Codeforces 580C Kefa and Park(dfs)
- codeforces 580C(Kefa and Park, 搜索类型题)
- CodeForces 580C Kefa and Park(DFS)
- Codeforces 580C Kefa and Park【dfs】水题
- C. Kefa and Park
- Codeforces Round #321 (Div. 2)C. Kefa and Park
- Codeforces#321 (Div. 2) C. Kefa and Park(dfs)
- Codeforces Round #321 (Div. 2)C. Kefa and Park
- Codeforces Round #321 (Div. 2) C. Kefa and Park dfs
- Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)
- CF#321-C - Kefa and Park-DFS
- Codeforces Round #321 (Div. 2) C. Kefa and Park time limit per test
- Codeforces Round #321 (Div. 2) C. Kefa and Park time limit per test
- js正则表达式
- asp操作数据库以及文本文件
- 5种服务器网络编程模型讲解
- 16. 3Sum Closest
- 协方差矩阵及matlab实现
- codeforces 580C Kefa and Park
- Mac 开发 打开系统偏好设置
- javap -c 命令大全
- C# WinForm开发系列
- 纯DIV+CSS实现进度条
- ubuntu IP 出现 inet6 addr :fe80::20c:29ff:fe47:fd61/64 scope:link1
- 用idea搭建struts2.5
- C++11基础-----Auto关键字及注意点
- git rebase 过程中解决冲突conflic