#include <bits/stdc++.h>
#define qwq printf("qwq")
#define N 100010
using namespace std;
int n, m;
long long ans;
struct Node{int val, first, vis;} node[N];
struct Edge{int next, to;} edge[N];
void add_edge(int u, int v, int cnt)
{
edge[cnt].to = v, edge[cnt].next = node[u].first;
node[u].first = cnt;
}
void search(int curr, int cnt)
{
if (cnt > m) return;
node[curr].vis = 1;
int flag = 0;
for (int i = node[curr].first; i; i = edge[i].next)
{
int res = edge[i].to;
if (!node[res].vis)
{
flag = 1;
search(res, node[res].val ? (cnt + 1) : 0);
}
}
if (!flag && cnt <= m) ans++;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &node[i].val);
for (int i = 1; i < n; i++)
{
int x, y; scanf("%d%d", &x, &y);
add_edge(x, y, i); add_edge(y, x, i + n);
}
search(1, node[1].val);
printf("%lld\n", ans);
return 0;
}
第14个测试点错了,错误信息是
first numbers differ-expected: '33716', found: '0'