CF580C

说句实话,这道题作为蓝题过于简单了一点

#include<iostream>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define fi(i,a,b) for(int i = a; i <= b; ++i)
#define fr(i,a,b) for(int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int,int>;
//#define DEBUG
const int N = 1e5 + 5;
int n,m;
vector<int> vec[N];
int w[N];
bool vis[N];
int ans;
void dfs(int x,int y){
    vis[x] = true;
    if(y > m) return;
    if(sz(vec[x]) == 1 && x != 1) {ans++;return;}
    fi(i,0,sz(vec[x]) - 1){
        if(vis[vec[x][i]]) continue;
        if(w[vec[x][i]]) dfs(vec[x][i],y+1);
        else dfs(vec[x][i],0);
    }
    vis[x] = false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    fi(i,1,n) cin >> w[i];
    fi(i,1,n-1) {
        int a,b;
        cin >> a >> b;
        vec[a].pb(b);
        vec[b].pb(a);
    }
    dfs(1,w[1]);
    cout << ans << endl;
#ifdef DEBUG
    //freopen(D:\in.txt,r,stdin);
#endif
    return 0;
}
posted @   Sun-Wind  阅读(48)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示