/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
unordered_map<ll, ll> a;
vector<long long> adj[N];

void dfs(ll root, ll tc, ll cost, ll par){
    if(cost>m) return;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;
    if(cost > m) return;
    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(it!=par) dfs(it, tc, cost, root);
        //cout<<it<<" hi "<<root<<" ki "<<cost<<br;

    }
}

void solve(){
    cin>>n>>m;
    ll xx;
    for(ll i=1; i<=n; i++){
        cin>>xx;
        if(xx) a[i]=1;
    }

    ll x, y;
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    dfs(1, 0, 0, -1);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
unordered_map<ll, ll> a;
bool vis[N];

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost){
    vis[root] = 1;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;
    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(vis[it]) continue;
        dfs(adj, it, tc, cost);
    }
}

void solve(){
    cin>>n>>m;
    ll xx;
    for(ll i=1; i<=n; i++){
        cin>>xx;
        if(xx) a[i]=1;
    }

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    for(ll i=0; i<=n; i++) vis[i] = 0;
    dfs(adj, 1, 0, 0);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
unordered_map<ll, ll> a;
bool vis[N];

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost){
    vis[root] = 1;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;
    if(cost > m) return;
    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(vis[it]) continue;
        dfs(adj, it, tc, cost);
    }
}

void solve(){
    cin>>n>>m;
    ll xx;
    for(ll i=1; i<=n; i++){
        cin>>xx;
        if(xx) a[i]=1;
    }

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    for(ll i=0; i<=n; i++) vis[i] = 0;
    dfs(adj, 1, 0, 0);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
unordered_map<ll, ll> a;

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost, ll par){
    if(cost>m) return;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;
    if(cost > m) return;
    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(it!=par) dfs(adj, it, tc, cost, root);
        //cout<<it<<" hi "<<root<<" ki "<<cost<<br;

    }
}

void solve(){
    cin>>n>>m;
    ll xx;
    for(ll i=1; i<=n; i++){
        cin>>xx;
        if(xx) a[i]=1;
    }

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    dfs(adj, 1, 0, 0, -1);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
ll a[N];
bool vis[N];

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost){
    vis[root] = 1;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;

    if(adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(vis[it]) continue;
        dfs(adj, it, tc, cost);
    }
}

void solve(){
    cin>>n>>m;
    for(ll i=1; i<=n; i++) cin>>a[i];

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    for(ll i=0; i<(ll)1e5 + 5; i++) vis[i] = 0;
    dfs(adj, 1, 0, 0);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
ll a[N];
bool vis[N];

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost){
    vis[root] = 1;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;

    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(vis[it]) continue;
        dfs(adj, it, tc, cost);
    }
}

void solve(){
    cin>>n>>m;
    for(ll i=1; i<=n; i++) cin>>a[i];

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    for(ll i=0; i<(ll)1e5 + 5; i++) vis[i] = 0;
    dfs(adj, 1, 0, 0);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans = 0;

void check(vector <int>v[], vector<int> cat, int count, int i, int m)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(v,cat,count,v[i][j],m);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    vector <int> cat(123456);

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    vector <int>v[123456];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(v,cat,0,1,m);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans = 0;

void check(vector <int>v[], vector<int> cat, int count, int i, int m)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;j++)
    {
        if(!vis[v[i][j]])
            check(v,cat,count,v[i][j],m);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    vector <int> cat(123456);

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    vector <int>v[123456];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(v,cat,0,1,m);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans=0;
vector <int>v[123456];
vector <int> cat(123456);

void check(int count, int i, int m)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(count,v[i][j],m);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(0,1,m);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans;
vector <int> cat(123456);
vector <int>v[123456];
int m;

void check(int count, int i)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(count,v[i][j]);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(0,1);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans=0;
vector <int>v[123456];
vector <int> cat(123456);

void check(vector <int> cat,int count, int i, int m)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(cat,count,v[i][j],m);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(cat,0,1,m);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans=0;
int cat[123456];
vector <int>v[123456];

void check(int count, int i, int m)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(count,v[i][j],m);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(0,1,m);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans=0;
vector <int>v[123456];
vector <int> cat(123456);

void check(vector <int> &cat,int count, int i, int m)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(cat,count,v[i][j],m);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(cat,0,1,m);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,ans;
std::vector<int> p[100009];
bool vis[100009],cats[1000009],h[1000009];
set<int> s;
void dfs(int u=1,int c=0)
  {
    // cout<<u<<endl;
    if(cats[u])++c;else c=0;
    if(c>m)return;
    vis[u]=1;
    int si=p[u].size();
    if(si==1 && u>1){ans+=1;return ;}
    for(int i=0;i<si;++i)
        if(!vis[p[u][i]])
          dfs(p[u][i],c);
  }
int main()
{
    scanf("%d %d",&n,&m );
    for(int i=1;i<=n;i++)cats[i]=(scanf("%d",&a ),a);

    for(int i=0;i<n-1;i++)
      {
        scanf("%d %d",&a,&b );
        p[a].push_back(b);
        p[b].push_back(a);
      }
        dfs();
      // int ans=0;
      // for(int i=2;i<=n;i++)
      //   ans+=(h[i]&&vis[i]);
      // for(int i=2;i<=n;i++)
        // cout<<p[i].size()<<' ';
      printf("%d\n",ans );
}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans=0;
vector <int>v[123456];

void check(vector <int> cat,int count, int i, int m)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(cat,count,v[i][j],m);
    }

}

void solve()
{
    int n,m;
    cin>>n>>m;

    vector <int> cat(123456);

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(cat,0,1,m);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans=0;
vector <int>v[123456];
int m;

void check(int cat[], int count, int i)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(cat,count,v[i][j]);
    }

}

void solve()
{
    int n;
    cin>>n>>m;

    int cat[123456];

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(cat,0,1);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);	cin.tie(NULL); cout.tie(NULL);
#define asc(s) sort(s.begin(),s.end())
#define des(s) sort(s.rbegin(),s.rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x,p) fixed<<setprecision(p)<<x
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debugn(x) cout<<"Debug : "<<x<<endl;
#define debug(x) cout<<x<<' ';
#else
#define debug(x)
#define debugn(x)
#endif

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string>beg(buf), end;
    vector<string>list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if(find(s.begin(),s.end(), c) != s.end()) return true;
    return false;
}

bool cmp(pair <int,int> &a, pair <int,int> &b)
{
    return a.second > b.second || (a.second==b.second && a.first>b.first);
}

int vis[123456];
int ans=0;
int cat[123456];
vector <int>v[123456];
int m;

void check(int count, int i)
{

    if(cat[i]) ++count;
    else count=0;

    if(count>m) return;

    vis[i] = 1;
    int si = v[i].size();
    if(si==1 && i>1)
    {
        ans+=1;
        return;
    }

    for(int j=0;j<si;++j)
    {
        if(!vis[v[i][j]])
            check(count,v[i][j]);
    }

}

void solve()
{
    int n;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>cat[i];

    for(int i=0,a,b;i<n-1;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    check(0,1);

    cout<<ans;

}

int main()
{

    fastIO

    int t=1;
    // cin>>t;

    for(int test_case=1;test_case<=t;test_case++)
    {
        solve();
    }
        return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
int maxi = 0;
void dfs(int node, int prev, int cur, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		//cout << maxi<<" "<<cur<<" "<<m << endl;
		if (max(maxi, cur) <= m) cnt++;
	}
	else if (cat[node] == 0)
	{
		maxi = max(maxi, cur);
		cur = 0;
	}
	for (auto child : edges[node])
	{
		if (child != prev)
				dfs(child, node, cur + cat[child], edges, cat);
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1], edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
//int maxi = 0;
void dfs(int node, int prev, int cur,int maxi, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		if (maxi <= m) cnt++;
	}

	for (auto child : edges[node])
	{
		if (child != prev)
		{
			if (cat[node] == 0)
				dfs(child, node, 0+cat[child], max(maxi, cur), edges, cat);
			else
			dfs(child, node, cur + cat[child], max(maxi, cur + cat[child]), edges, cat);
		}
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1],0, edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
//int maxi = 0;
void dfs(int node, int prev, int cur,int maxi, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		//cout << maxi<<" "<<cur<<" "<<m << endl;
		if (max(maxi, cur) <= m) cnt++;
	}
	/*else if (cat[node] == 0)
	{
		maxi = max(maxi, cur);
		cur = 0;
	}*/
	for (auto child : edges[node])
	{
		if (child != prev)
		{
			if (cat[node] == 0)
				dfs(child, node, 0, max(maxi, cur), edges, cat);
			else
			dfs(child, node, cur + cat[child], max(maxi, cur + cat[child]), edges, cat);
		}
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1],0, edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int cnt = 0;
void dfs(int m,int root, int parent, int n, vector<vii > & edges,vii &cat,int num_of_cats)
{

	for (auto child : edges[root])
	{
		if (child != parent)
		{
			if (cat[child] && cat[parent])
				dfs(m, child, root, n, edges, cat, num_of_cats + cat[child]);
			else if (cat[child] && !cat[parent])
				dfs(m, child, root, n, edges, cat, cat[child]);
			else if (edges[child].size() == 1)
				dfs(m, child, root, n, edges, cat, num_of_cats);
			else
				dfs(m, child, root, n, edges, cat, 0);
		}
	}
	//cout << root<<' '<<parent << endl;
	//cout << num_of_cats << endl;
	if (num_of_cats <= m&&edges[root].size()==1) cnt++;
	//cout << "cnt= " << cnt << endl;
}
signed main()
{
	fast;
	int t = 1, n, m, u, v;
	int num_of_cats=0;
	cin >> n >> m;
	vii cat(n + 5);
	vector<vii > edges(n + 5);
	fori(1, n + 1) cin >> cat[i];
	fori(1, n)
	{
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}

	dfs(m, 1, -1, n, edges, cat, cat[1]);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
void dfs(int node, int prev, int cur, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		if (cat[node] == 1) cur--;
		if (cur <= m) cnt++;
	}
	for (auto child : edges[node])
	{
		if (child != prev)
		{
			dfs(child, node, cur+cat[child], edges, cat);
		}
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1], edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
int maxi = 0;
void dfs(int node, int prev, int cur, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		int temp = maxi;
		maxi = max(maxi, cur);
		//cout << maxi<<" "<<m << endl;
		if (maxi <= m) cnt++;
		maxi = temp;
	}
	if (cat[node] == 0)
	{
		maxi = max(maxi, cur);
		cur = 0;
	}
	for (auto child : edges[node])
	{
		if (child != prev)
				dfs(child, node, cur + cat[child], edges, cat);
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1], edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
int maxi = 0;
void dfs(int node, int prev, int cur, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		maxi = max(maxi, cur);
		if (cur <= m) cnt++;
	}
	if (cat[node] == 0)
	{
		maxi = max(maxi, cur);
		cur = 0;
	}

	for (auto child : edges[node])
	{
		if (child != prev)
		{
				dfs(child, node, cur + cat[child], edges, cat);
		}
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1], edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
//int maxi = 0;
void dfs(int node, int prev, int cur,int maxi, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		if (maxi <= m) cnt++;
	}

	for (auto child : edges[node])
	{
		if (child != prev)
		{
			if (cat[node] == 0)
				dfs(child, node, 0, max(maxi, cur), edges, cat);
			else
			dfs(child, node, cur + cat[child], max(maxi, cur + cat[child]), edges, cat);
		}
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1],0, edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int n, m, u, v;
int cnt = 0;
//int maxi = 0;
void dfs(int node, int prev, int cur,int maxi, vector<vii>& edges, vii& cat)
{
	if (edges[node].size()==1 && node != 1)//base case
	{
		//cout << maxi<<" "<<cur<<" "<<m << endl;
		if (max(maxi, cur) <= m) cnt++;
	}
	/*else if (cat[node] == 0)
	{
		maxi = max(maxi, cur);
		cur = 0;
	}*/
	for (auto child : edges[node])
	{
		if (child != prev)
		{
			if (cat[node] == 0)
				dfs(child, node, 0, max(maxi, cur), edges, cat);
			else
			dfs(child, node, cur + cat[child], max(maxi, cur), edges, cat);
		}
	}
}
signed main()
{
	fast;
	cin >> n >> m;
	vii cat(n + 1);
	vector<vii> edges(n + 1);
	fori(1, n+1) cin >> cat[i];
	fori(1,n){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(1, 0, cat[1],0, edges, cat);
	cout << cnt << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++)
#define forj(s,n) for(int j=s;j<n;j++)
#define vii vector<int>
int cnt = 0;
void dfs(int m,int root, int parent, int n, vector<vii > & edges,vii &cat,int num_of_cats)
{

	for (auto child : edges[root])
	{
		if (child != parent)
		{
			if (cat[child] && cat[parent])
				dfs(m, child, root, n, edges, cat, num_of_cats + cat[child]);
			else if (cat[child] && !cat[parent])
				dfs(m, child, root, n, edges, cat, cat[child]);
			else if (edges[child].size() == 1 && edges[root][0] == parent)
				dfs(m, child, root, n, edges, cat, num_of_cats);
			else
				dfs(m, child, root, n, edges, cat, 0);
		}
	}
	//cout << root<<' '<<parent << endl;
	//cout << num_of_cats << endl;
	//cout << edges[root].size() << endl;
	if (num_of_cats <= m&&edges[root].size()==1&&edges[root][0]==parent) cnt++;
	//cout << "cnt= " << cnt << endl;
}
signed main()
{
	fast;
	int t = 1, n, m, u, v;
	int num_of_cats=0;
	cin >> n >> m;
	vii cat(n + 5);
	vector<vii > edges(n + 5);
	fori(1, n + 1) cin >> cat[i];
	fori(1, n)
	{
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}

	dfs(m, 1, -1, n, edges, cat, cat[1]);
	cout << cnt << endl;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=100001;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
ll cv=0;

void dfs(ll k,vector<int>a,ll m,ll cn)
{
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==1&&k!=0){
			cv++;
			return;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	vector<int>a(n);
	input(a,n);
	fof(i,0,n-1){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		Dfs[x].pb(y);
		Dfs[y].pb(x);
	}
	dfs(0,a,m,0);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=228228;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<ll> Dfs[N];
long long c[N],o,x,y,i,j,n,m;
ll cv=0,countt=0;

void dfs(ll k,ll a[],ll m,ll cn)
{
	countt++;
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==1&&k!=0){
			cv++;
			return;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{

	cin>>n>>m;
	for(i=0;i<n;i++)scanf("%d",&c[i]);
	for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,Dfs[x].pb(y),Dfs[y].pb(x);
	dfs(0,c,m,0);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
//const int N=100001;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
const long long A=100000000000000LL,N=228228;

vector<long long> a[N];
long long c[N],o,x,y,i,j,n,m;

void go(int v,int pr,int k){
	if(k>m)return;
	int ok=1;
	for(int i=0;i<a[v].size();i++)if(a[v][i]!=pr)ok=0,go(a[v][i],v,k*c[a[v][i]]+c[a[v][i]]);
	o+=ok;
}

void solve(){
	cin>>n>>m;
	for(i=0;i<n;i++)scanf("%d",&c[i]);
	for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,a[x].pb(y),a[y].pb(x);
	go(0,-1,c[0]);
	cout<<o<<"\n";
}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=228228;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
ll cv=0,countt=0;

void dfs(ll k,vector<int>a,ll m,ll cn)
{
	countt++;
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==1&&k!=0){
			cv++;
			return;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	vector<int>a(n);
	input(a,n);
	fof(i,0,n-1){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		Dfs[x].pb(y);
		Dfs[y].pb(x);
	}
	dfs(0,a,m,0);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=100001;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
vector<int>a(N);
ll cv=0;
ll o,m;

void go(int v,int pr,int k){
	if(k>m)return;
	int ok=1;
	for(int i=0;i<Dfs[v].size();i++)if(Dfs[v][i]!=pr)ok=0,go(Dfs[v][i],v,k*a[Dfs[v][i]]+a[Dfs[v][i]]);
	o+=ok;
}
void solve()
{
	ll n;
	cin>>n;
	cin>>m;

	input(a,n);
	fof(i,0,n-1){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		Dfs[x].pb(y);
		Dfs[y].pb(x);
	}
	go(0,-1,a[0]);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

vector<long long> a[N];
long long c[N],o,x,y,i,j,n,m;

void go(int v,int pr,int k){
	if(k>m)return;
	int ok=1;
	for(int i=0;i<a[v].size();i++)if(a[v][i]!=pr)ok=0,go(a[v][i],v,k*c[a[v][i]]+c[a[v][i]]);
	o+=ok;
}

int main(){
	cin>>n>>m;
	for(i=0;i<n;i++)scanf("%d",&c[i]);
	for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,a[x].pb(y),a[y].pb(x);
	go(0,-1,c[0]);
	cout<<o<<"\n";
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=100001;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
ll cv=0;

void dfs(ll k,vector<int>a,ll m,ll cn)
{
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==0){
			cv++;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	vector<int>a(n);
	input(a,n);
	fof(i,0,n-1){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		if(y==0){
			swap(x,y);
		}
		Dfs[x].pb(y);
	}
	dfs(0,a,m,0);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
//const int N=100001;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
const long long A=100000000000000LL,N=228228;

vector<long long> a[N];
long long c[N],o,x,y,i,j,n,m;

void go(int v,int pr,int k){
	if(k>m)return;
	int ok=1;
	for(int i=0;i<a[v].size();i++)if(a[v][i]!=pr)ok=0,go(a[v][i],v,k*c[a[v][i]]+c[a[v][i]]);
	o+=ok;
}

void solve(){
	cin>>n>>m;
	for(i=0;i<n;i++)scanf("%d",&c[i]);
	for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,a[x].pb(y),a[y].pb(x);
	go(0,-1,c[0]);
	cout<<o<<"\n";
}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		//cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=228228;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
ll cv=0,countt=0;

void dfs(ll k,vector<int>a,ll m,ll cn)
{
	countt++;
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==1&&k!=0){
			cv++;
			return;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	vector<int>a(n);
	input(a,n);
	fof(i,0,n-1){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		Dfs[x].pb(y);
		Dfs[y].pb(x);
	}
	dfs(0,a,m,0);
	cout<<cv<<" "<<countt;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
//const int N=100001;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
const long long A=100000000000000LL,N=228228;

vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
ll cv=0;
long long c[N],o,x,y,i,j,n,m;

void go(ll k,ll a[],ll m,ll cn)
{
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==1&&k!=0){
			cv++;
			return;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				go(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}

void solve(){
	cin>>n>>m;
	for(i=0;i<n;i++)scanf("%d",&c[i]);
	for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,Dfs[x].pb(y),Dfs[y].pb(x);
	go(0,c,m,0);
	cout<<cv<<"\n";
}
int main()
{
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=228228;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
ll cv=0,countt=0;

void dfs(ll k,ll a[],ll m,ll cn)
{
	countt++;
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==1&&k!=0){
			cv++;
			return;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{
	ll n,m,i,x,y,c[N];
	cin>>n>>m;
	for(i=0;i<n;i++)scanf("%d",&c[i]);
	for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,Dfs[x].pb(y),Dfs[y].pb(x);
	dfs(0,c,m,0);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=100001;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<int> Dfs[N];
ll cv=0;

void dfs(ll k,vector<int>a,ll m,ll cn)
{
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==0){
			cv++;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	vector<int>a(n);
	input(a,n);
	fof(i,0,n-1){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		Dfs[x].pb(y);
	}
	dfs(0,a,m,0);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// numbers
#define MOD 1000000007
const int N=228228;
const int INF=100000000;
//shortforms
#define ff first
#define ss second
#define ll long long int
#define pb(a) push_back((a))
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
#define fom(i,a,n) for(auto i=a;i!=(n);i++)
//sorting
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mai(n,M) fof(i,0,n){ll  a; cin>>a;  if(M.find(a)==M.end()){ M.mk_pair(ll,ll,a,1); } else { M[a]++;} }
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
//output
#define debug(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
//code begins
vector< int> visited(N,0),cnt(N,0);
vector<ll> Dfs[N];
long long c[N],o,x=0,y=0,i=0,j,n=0,m=0;
ll cv=0,countt=0;

void dfs(ll k,ll a[],ll m,ll cn)
{
	countt++;
	if(visited[k]==0)
	{
		// process node k
		visited[k]=1;
		if(a[k]==1){
			//cout<<"hi";
			cnt[k]=cn+1;
		}
		if(cnt[k]>m){
			return;
		}
		if(Dfs[k].size()==1&&k!=0){
			cv++;
			return;
		}
		fof(i,0,Dfs[k].size())
		{
			if(!visited[Dfs[k][i]])
			{
				dfs(Dfs[k][i],a,m,cnt[k]);
			}
		}
	}
}
void solve()
{

	cin>>n>>m;
	for(i=0;i<n;i++)scanf("%d",&c[i]);
	for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,Dfs[x].pb(y),Dfs[y].pb(x);
	dfs(0,c,m,0);
	cout<<cv;

}
void template1 ()
{
	ll t;
	cin>>t;
	while(t--)
	{
		solve();
		cout<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//template1();
	solve();cout<<"\n";
	return 0;
}


#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    long long ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i];
    }
    for(long long i = 1; i < n; i++){
        long long x,y;
        cin >> x >> y;
        ai[y] += ai[x];
        if(ai[y] <= m){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    long long ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i];
    }
    for(long long i = 1; i < (n-1); i++){
        long long x,y;
        cin >> x >> y;
        a[y] += a[x];
        if(a[y] <= m){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    long long ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i];
    }
    for(long long i = 1; i < (n-1); i++){
        long long x,y;
        cin >> x >> y;
        ai[y] += ai[x];
        if(ai[y] <= m){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <utility>
#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    pair<long long, bool> ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i].first;
        ai[i].second = false;
    }
    for(long long i = 1; i < n; i++){
        long long x,y;
        cin >> x >> y;
        if(!ai[x].second){ai[x].second = true;}
        if(ai[x].first > m){
            ai[y].first = m;
        }
        else{
            if(ai[y].first == 1){
                ai[y].first += ai[x].first;
            }
        }
    }
    for(long long i = 1; i <= n; i++){
        if(ai[i].second == false && ai[i].first <= m){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <utility>
#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    pair<long long, bool> ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i].first;
        ai[i].second = false;
    }
    for(long long i = 1; i < n; i++){
        long long x,y;
        cin >> x >> y;
        if(!ai[x].second){ai[x].second = true;}
        if(ai[x].first > m){
            ai[y].first = ai[x].first;
        }
        else{
            if(ai[y].first == 1){
                ai[y].first += ai[x].first;
            }
        }
    }
    for(long long i = 1; i <= n; i++){
        if(ai[i].second == false && ai[i].first <= m){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <utility>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    pair<long long, pair<bool,bool>> ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i].first;
        ai[i].second.first = false; //father?
        ai[i].second.second = false; // activated?
    }
    vector<pair<long long, long long>> xy;
    for(long long i = 0; i < n-1; i++){
        long long x, y;
        cin >> x >> y;
        if(x > y){
            long long t = x;
            x = y;
            y = t;
        }
        xy.push_back(make_pair(x,y));
    }
    sort(xy.begin(), xy.end());
    ai[1].second.second = true;
    for(long long i = 0; i < n-1; i++){
        long long x,y;
        x = xy[i].first;
        y = xy[i].second;
        if(ai[y].second.second){
            ai[y].second.first = true;
            ai[x].second.second = true;
            long long t = x;
            x = y;
            y = t;
        }
        else{
            if(!ai[x].second.first){
                ai[x].second.first = true;
                ai[x].second.second = true;
            }
            ai[y].second.second = true;
        }
        if(ai[x].first > m){
            ai[y].first = ai[x].first;
        }
        else{
            if(ai[y].first == 1){
                ai[y].first += ai[x].first;
            }
        }
    }
    for(long long i = 1; i <= n; i++){
        if(ai[i].second.first == false && ai[i].first <= m){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <utility>
#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    pair<long long, bool> ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i].first;
        ai[i].second = false;
    }
    for(long long i = 1; i < n; i++){
        long long x,y;
        cin >> x >> y;
        if(!ai[x].second){ai[x].second = true;}
        if(ai[x].first > m){
            ai[y].first = m;
        }
        else{
            if(ai[y].first == 1){
                ai[y].first += ai[x].first;
            }
        }
    }
    for(long long i = 1; i <= n; i++){
        if(ai[i].second == false){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <utility>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
    long long n,m,r=0;
    cin >> n >> m;
    pair<long long, pair<bool,bool>> ai[n+1];
    for(long long i = 1; i <= n; i++){
        cin >> ai[i].first;
        ai[i].second.first = false; //father?
        ai[i].second.second = false; // activated?
    }
    vector<pair<long long, long long>> xy;
    for(long long i = 0; i < n-1; i++){
        long long x, y;
        cin >> x >> y;
        if(x > y){
            long long t = x;
            x = y;
            y = t;
        }
        xy.push_back(make_pair(x,y));
    }
    sort(xy.begin(), xy.end());
    for(long long i = 0; i < n-1; i++){
        long long x,y;
        x = xy[i].first;
        y = xy[i].second;
        if(ai[y].second.second){
            ai[y].second.first = true;
            ai[x].second.second = true;
            long long t = x;
            x = y;
            y = t;
        }
        else{
            ai[x].second.first = true;
            ai[x].second.second = true;
            ai[y].second.second = true;
        }
        if(ai[x].first > m){
            ai[y].first = ai[x].first;
        }
        else{
            if(ai[y].first == 1){
                ai[y].first += ai[x].first;
            }
        }
    }
    for(long long i = 1; i <= n; i++){
        if(ai[i].second.first == false && ai[i].first <= m){
            r++;
        }
    }
    cout << r << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <bitset>
#include <vector>
using namespace std;

const int MAXN = 1e5 + 3;

int m;
bitset<MAXN> hasCat;
vector<vector<int> > adjList;
int ans, maxx[MAXN] = {0}, curr[MAXN] = {0};

void dfs(int u, int par = 0)
{
    if(hasCat[u])
        curr[u] = 1 + ((hasCat[par])? curr[par] : 0);
    else
        curr[u] = 0;

    maxx[u] = max(curr[u], maxx[par]);

    bool isLeaf = true;

    for(auto &v : adjList[u]) {
        if(v != par) {
            dfs(v, u);
            isLeaf = false;
        }
    }

    if(isLeaf and maxx[u] <= m) ++ans;
}

int main()
{
    //freopen("in.txt", "r", stdin);

    int n;
    scanf("%d %d", &n, &m);

    int tmp;

    for(int i = 1; i <= n; ++i) {
        scanf("%d", &tmp);
        hasCat[i] = tmp;
    }

    adjList.resize(n+3);
    int u, v;

    for(int i = 1; i < n; ++i) {
        scanf("%d %d", &u, &v);
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }

    ans = 0;
    dfs(1);

    printf("%d\n", ans);

    return 0;
}


//this solution has been posted by shahed-shd on github.com
// ----------------

#include <algorithm>
#include <bitset>
#include <vector>
#include <iostream>
using namespace std;

const int MAXN = 1e5 + 3;

int m;
bitset<MAXN> hasCat;
vector<vector<int> > adjList;
int ans, maxx[MAXN] = {0}, curr[MAXN] = {0};

void dfs(int u, int par = 0){
    if(hasCat[u]) //first try always true
        curr[u] = 1 + ((hasCat[par])? curr[par] : 0);
    else
        curr[u] = 0;
    maxx[u] = max(curr[u], maxx[par]);
    bool isLeaf = true;
    for(auto &v : adjList[u]){
        if(v != par){
            dfs(v, u);
            isLeaf = false;
        }
    }
    if(isLeaf && maxx[u] <= m) ans++;
}

int main(){
    int n,tmp,u,v;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> tmp;
        hasCat[i] = tmp;
    }
    adjList.resize(n+3); //it sets the values of the relation tree
    for(int i = 1; i < n; i++){
        cin >> u >> v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }
    ans = 0;
    dfs(1);
    cout << ans << endl;
    return 0;
}


//this solution has been posted by shahed-shd on github.com
// ----------------

#include <algorithm>
#include <bitset>
#include <vector>
#include <iostream>
using namespace std;

const int MAXN = 1e5 + 3;

int m;
bitset<MAXN> hasCat;
vector<vector<int> > adjList;
int ans, maxx[MAXN] = {0}, curr[MAXN] = {0};

void dfs(int u, int par = 0){
    if(hasCat[u]) //first try always true
        curr[u] = 1 + ((hasCat[par])? curr[par] : 0);
    else
        curr[u] = 0;
    maxx[u] = max(curr[u], maxx[par]);
    bool isLeaf = true;
    for(auto &v : adjList[u]){
        if(v != par){
            dfs(v, u);
            isLeaf = false;
        }
    }
    if(isLeaf && maxx[u] <= m) ans++;
}

int main(){
    int n,tmp,u,v;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> tmp;
        hasCat[i] = tmp;
    }
    adjList.resize(n+3); //it sets the values of the relation tree
    for(int i = 1; i < n; i++){
        cin >> u >> v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }
    ans = 0;
    dfs(1);
    cout << ans << endl;
    return 0;
}


//this solution has been posted by shahed-shd on github.com
// ----------------

#include <algorithm>
#include <bitset>
#include <vector>
#include <iostream>
using namespace std;

const int MAXN = 1e5 + 3;

int m;
bitset<MAXN> hasCat;
vector<vector<int> > adjList;
int ans, maxx[MAXN] = {0}, curr[MAXN] = {0};

void dfs(int u, int par = 0){
    if(hasCat[u]) //first try always true
        curr[u] = 1 + ((hasCat[par])? curr[par] : 0);
    else
        curr[u] = 0;
    maxx[u] = max(curr[u], maxx[par]);
    bool isLeaf = true;
    for(auto &v : adjList[u]){
        if(v != par){
            dfs(v, u);
            isLeaf = false;
        }
    }
    if(isLeaf && max[u] <= m) ans++;
}

int main(){
    int n,tmp,u,v;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> tmp;
        hasCat[i] = tmp;
    }
    adjList.resize(n+3); //it sets the values of the relation tree
    for(int i = 1; i < n; i++){
        cin >> u >> v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }
    ans = 0;
    dfs(1);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int s=0,m,n,t[100000],test=0;
vector<vector<int>> g;
bool visited[100000];
void dfs(int u,int v)
{
    if(v>m)
        return ;
    visited[u]=1;
    if(g[u].size()==1&&visited[g[u][0]])
       {
        if(v<=m){

            s++;
        }

       }
    else
    {
            for(int i=0;i<g[u].size();i++){
                    if(!visited[g[u][i]])
                    dfs(g[u][i],(t[g[u][i]]? v+1: 0));
            }

    }

}

int main()
{int a,b;
    cin>>n>>m;
    g.resize(n+1);
    for(int i=1;i<=n;i++)
        cin>>t[i];

    for(int i=0;i<n-1;i++){
      cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);

      }

    dfs(1,t[1]);
    cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int s=0,m,n,t[100005],test=0;
vector<vector<int>> g;
bool visited[100005];
void dfs(int u,int v)
{
    if(v>m)
        return ;
    visited[u]=1;
    if(g[u].size()==1&&visited[g[u][0]])
       {
        if(v<=m){

            s++;
        }

       }
    else
    {
            for(int i=0;i<g[u].size();i++){
                    if(!visited[g[u][i]])
                    dfs(g[u][i],(t[g[u][i]]? v+1: 0));
            }

    }

}

int main()
{int a,b;
    cin>>n>>m;
    g.resize(n+1);
    for(int i=1;i<=n;i++)
        cin>>t[i];

    for(int i=0;i<n-1;i++){
      cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);

      }

    dfs(1,t[1]);
    cout<<s;
}


#include <bits/stdc++.h>
using namespace std;

int nb=0,mb=0;
vector<bool> visited;
vector<vector<int> > v,v1;
int k=0;
int t[100005];
int m,n,i,x,y,p,mi,ma,j,val=0;

void dfs(int node){
    int i;
    visited[node]=true;
    if(t[node-1]==1)
        nb++;
    else
        nb=0;
    if(nb>m)
        return;
    if((v[node].size()<2)&&(node!=1))
    {
            val++;
            nb=p;
            return;
        }

    for(i=0;i<v[node].size();i++)
        if(!visited[v[node][i]])
                dfs(v[node][i]);

}
int main(){

    cin>>n>>m;
    visited.resize(n+1);
    v.resize(n+1);
    for(i=0;i<n;i++){
        cin>>t[i];
    }
    for(i=0;i<n-1;i++){
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    if(t[0]==1)
        p=1;
    else
        p=0;
    dfs(1);
    cout<<val;
}


#include<bits/stdc++.h>
using namespace std;
int s=0,m,n,t[100005],test=0;
vector<vector<int>> g;
bool visited[100005];
void dfs(int u,int v,int pere)
{   visited[u]=1;
    if(t[u]==1&&pere==1){
        pere=1;
        v++;
    }
    else if(t[u]==1&&pere==0){
        pere=1;
        v=1;
    }
    else if(t[u]==0){
        pere=0;
        v=0;
    }
    if(v>m)
        return ;

    if(g[u].size()==1&&visited[g[u][0]])
       {
        if(v<=m){

            s++;
        }

       }
    else
    {
            for(int i=0;i<g[u].size();i++){
                    if(!visited[g[u][i]])
                    dfs(g[u][i],v,pere);
            }

    }

}

int main()
{int a,b;
    cin>>n>>m;
    g.resize(n+1);
    for(int i=1;i<=n;i++)
        cin>>t[i];

    for(int i=0;i<n-1;i++){
      cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);

      }

    dfs(1,0,t[1]);
    cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<ld,ld>
#define M 1000000007
int n,m;
vector<int> adj[100005];
bool visited[100005]={0};
int colour[100005]={0};
int cons[100005]={0};
int cnt=0;
void dfs(int s){
    visited[s]=true;
    int ch=0;
    for(auto u:adj[s]){
        if(visited[u]) continue;
        ch++;
        if(colour[u]==0) cons[u]=0;
        else cons[u]=cons[s]+1;

        if(cons[u]==m+1) continue;
        dfs(u);
    }
    if(ch==0) cnt++;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,a;
    cin>>n>>m;
    for(i=1;i<=n;i++) cin>>a,colour[i]=a;
    for(i=1;i<=n-1;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    cons[1]=colour[1];
    dfs(1);
    cout<<cnt;
}


#include <bits/stdc++.h>
using namespace std;

int nb=0,mb=0;
vector<bool> visited;
vector<vector<int> > v;
int t[100005];
int m,n,i,x,y,p;

void dfs(int node){
    int i;
    visited[node]=true;
    if((t[node-1]==1))
        nb++;
    else
        nb=0;
    if(nb>m) return ;
    if(v[node].size()==0){
        mb++;
        nb=p;
        return ;
    }
        for(i=0;i<v[node].size();i++)
            if(!visited[v[node][i]])
                dfs(v[node][i]);
}
int main(){

    cin>>n>>m;
    visited.resize(n+1);
    v.resize(n+1);
    for(i=0;i<n;i++){
        cin>>t[i];
    }
    for(i=0;i<n-1;i++){
        cin>>x>>y;
        v[x].push_back(y);
    }
    if(t[0]==1)
        p=1;
    else
        p=0;
    nb=0;
    dfs(1);
    cout<<mb;
}


#include <bits/stdc++.h>
using namespace std;

int nb=0,mb=0;
vector<bool> visited;
vector<vector<int> > v;
int t[100005];
int m,n,i,x,y,p,val;

void dfs(int node){
    int i;
    visited[node]=true;
    if((t[node-1]==1))
        nb++;
    else
        nb=0;
    if(nb>m) return ;
    if(v[node].size()==0){
        mb++;
        nb=p;
        return ;
    }
        for(i=0;i<v[node].size();i++)
            if(!visited[v[node][i]])
                dfs(v[node][i]);
}
int main(){

    cin>>n>>m;
    visited.resize(n+1);
    v.resize(n+1);
    for(i=0;i<n;i++){
        cin>>t[i];
    }
    for(i=0;i<n-1;i++){
        cin>>x>>y;
        if(i==0)
            val=x;
        v[x].push_back(y);
    }
    if(t[0]==1)
        p=1;
    else
        p=0;
    nb=0;
    dfs(val);
    cout<<mb;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<ld,ld>
#define M 1000000007
int n,m;
vector<int> adj[100005];
bool visited[100005]={0};
int colour[100005]={0};
int cons[100005]={0};
int cnt=0;
void dfs(int s){
    visited[s]=true;
    int ch=0;
    for(auto u:adj[s]){
        if(visited[u]) continue;
        if(colour[u]==0) cons[u]=0;
        else cons[u]=cons[s]+1;

        if(cons[u]==m+1) continue;
        ch++;
        dfs(u);
    }
    if(ch==0) cnt++;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,a;
    cin>>n>>m;
    for(i=1;i<=n;i++) cin>>a,colour[i]=a;
    for(i=1;i<=n-1;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    cons[1]=colour[1];
    dfs(1);
    cout<<cnt;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll ;
const int oo = 1e9;
int n,m,c[1000000],ans;

vector<vector<int> > g;
bool vis[100001],leaf;

void dfs(int u,int cat) {
    if(cat>m) return;
	vis[u] = 1;
    leaf=1;
	for (int i = 0; i < g[u].size(); i++)
		if (!vis[g[u][i]]){
			dfs(g[u][i],(c[g[u][i]]? cat+1 : 0));
            leaf=0;
		}
    if(leaf) ans++;
}

int main() {_
 cin >> n >> m;
	g.clear();
	g.resize(n+1);
    for(int i=1;i<=n;i++) cin >> c[i];
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	   dfs(1,c[1]);
    cout << ans ;
}


#include<bits/stdc++.h>
using namespace std;
int s=0,m,n,t[100005],test=0;
vector<vector<int>> g;
bool visited[100005];
void dfs(int u,int v,int pere)
{   visited[u]=1;
    if(t[u]==1&&pere==1){
        pere=1;
        v++;
    }
    else if(t[u]==1&&pere==0){
        pere=1;
        v=1;
    }
    else if(t[u]==0){
        pere=0;
        v=0;
    }
    if(v>m)
        return ;

    if(g[u].size()==1)
       {
        if(v<=m){

            s++;
        }

       }
    else
    {
            for(int i=0;i<g[u].size();i++){
                    if(!visited[g[u][i]])
                    dfs(g[u][i],v,pere);
            }

    }

}

int main()
{int a,b;
    cin>>n>>m;
    g.resize(n+1);
    for(int i=1;i<=n;i++)
        cin>>t[i];

    for(int i=0;i<n-1;i++){
      cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);

      }

    dfs(1,0,t[1]);
    cout<<s;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], vector<bool> cats, vector<bool> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 0) return 1;
    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
                else
                    return count;
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cats(n);
    vector<bool> visited(n);
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
    }

    /*for (int i = 1; i <= n; i++) {
        cout << i << ": ";
        for (unsigned int j = 0; j < adj[i].size(); j++) {
            cout << adj[i][j] << ", ";
        }
        cout << endl;
    }*/

    cout << dfs(adj, cats, visited, 1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], vector<bool> cats, vector<bool> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 0) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cats(n+1);
    vector<bool> visited(n+1);
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        if (child == 1) {
            child = parent;
            parent = 1;
        }
        adj[parent].push_back(child);
    }
    cout << dfs(adj, cats, visited, 1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], vector<bool> cats, vector<bool> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 0) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cats(n+1);
    vector<bool> visited(n+1);
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
    }

    cout << dfs(adj, cats, visited, 1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], vector<bool> cats, vector<bool> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 0) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        cout << visited[adj[v][i]] << endl;
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cats(n+1);
    vector<bool> visited(n+1);
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
    }

    cout << dfs(adj, cats, visited, 1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], set<int> cats, set<int> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 1 && v != 1) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited.count(adj[v][i])) {
            visited.insert(adj[v][i]);
            if (cats.count(adj[v][i])) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    set<int> cats;
    set<int> visited;
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats.insert(i);
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
        adj[child].push_back(parent);
    }

    visited.insert(1);
    cout << dfs(adj, cats, visited, 1, cats.count(1), m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], vector<bool> cats, vector<bool> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 1 && v != 1) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cats(n+1);
    vector<bool> visited(n+1);
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
        adj[child].push_back(parent);
    }
    visited[1] = true;
    cout << dfs(adj, cats, visited, 1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

vector<bool> cats(10001);
vector<bool> visited(100001);
vector<int> adj[100001];

int dfs(int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 1 && v != 1) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj[v][i], c + 1, m);
            } else {
                count += dfs(adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
        adj[child].push_back(parent);
    }
    visited[1] = true;
    cout << dfs(1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

vector<bool> cats(100001);
vector<bool> visited(100001);
vector<int> adj[100001];

int dfs(int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 1 && v != 1) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj[v][i], c + 1, m);
            } else {
                count += dfs(adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
        adj[child].push_back(parent);
    }
    visited[1] = true;
    cout << dfs(1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], vector<bool> cats, vector<bool> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 0) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cats(n+1);
    vector<bool> visited(n+1);
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        adj[parent].push_back(child);
        adj[child].push_back(parent);
    }

    cout << dfs(adj, cats, visited, 1, cats[1], m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int dfs(vector<int> adj[], vector<bool> cats, vector<bool> visited, int v, int c, int m) {
    int count = 0;
    if (adj[v].size() == 0) return 1;

    for (unsigned int i = 0; i < adj[v].size(); i++) {
        if (!visited[adj[v][i]]) {
            visited[adj[v][i]] = true;
            if (cats[adj[v][i]]) {
                if (c < m)
                    count += dfs(adj, cats, visited, adj[v][i], c + 1, m);
            } else {
                count += dfs(adj, cats, visited, adj[v][i], 0, m);
            }
        }
    }
    return count;
}

main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cats(n+1);
    vector<bool> visited(n+1);
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int cat;
        cin >> cat;
        if (cat) cats[i] = true;
    }

    for (int i = 1; i < n; i++) {
        int parent, child;
        cin >> parent >> child;
        if (parent > child) {
            parent = parent + child;
            child = parent - child;
            parent = parent - child;
        }
        adj[parent].push_back(child);
    }
    cout << dfs(adj, cats, visited, 1, cats[1], m);
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define MAX 1000
int counter=0;
int paths [MAX][MAX];

void searchForRestaurant(int cats[], bool isVisited[], int source, int totalCats , int maximum, int amount){

	int counterForCats=0;
	if (totalCats>maximum){
		return;
	}
	bool isLeaf=true;
	isVisited[source]=true;
	for (int j=1; j<=amount; j++){
		if (paths[source][j]!=-1 && isVisited[paths[source][j]]==false){
			if (cats[paths[source][j]]==1){
				counterForCats = totalCats+1;

			}
			else{
				counterForCats=0;
			}
			searchForRestaurant(cats, isVisited, j, counterForCats, maximum, amount);
			isLeaf=false;
		}

	}
	if (isLeaf){
		counter++;
	}
}

void initPaths(int amount){
	for (int i=1; i<=amount; i++){
		for (int j=1; j<=amount; j++){
			paths[i][j]=-1;
		}
	}
}

int main()
{
	int amount, maximum;
	cin>>amount>>maximum;
	int cats [amount+1];
	bool isVisited [amount+1];
	initPaths(amount+1);

	for (int i=1; i<=amount; i++){
		cin>>cats[i];
		isVisited[i]=false;
	}

	for (int i=0; i<amount-1; i++){
			int source, destination;
			cin>>source>>destination;

			paths[source][destination] = destination;
			paths[destination][source] = source;
	}

	searchForRestaurant(cats, isVisited, 1, cats[1], maximum, amount);
	cout<<counter;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define MAX 10000
int counter=0;
vector<vector<int> > paths (MAX);
int cats[MAX];
bool isVisited[MAX];
void searchForRestaurant(int source, int totalCats , int maximum, int amount){

	int counterForCats=0;
	isVisited[source]=true;
	if (totalCats>maximum){
		return;
	}
	bool isLeaf=true;
	for (int j=0; j < paths[source].size(); j++){
		if (!isVisited[paths[source][j]]){
			if (cats[paths[source][j]]==1){
				counterForCats = totalCats+1;
			}
			else{
				counterForCats=0;
			}
			searchForRestaurant(paths[source][j], counterForCats, maximum, amount);
			isLeaf=false;
		}

	}
	if (isLeaf){
		counter++;
	}
}

/*void initPaths(int amount){
	for (int i=1; i<=amount; i++){
		for (int j=1; j<=amount; j++){
			paths[i][j]=-1;
		}
	}
}*/

int main()
{
	int amount, maximum;
	cin>>amount>>maximum;
	int cats [amount+1];
	bool isVisited [amount+1];
	//initPaths(amount+1);

	for (int i=1; i<=amount; i++){
		cin>>cats[i];
		isVisited[i]=false;
	}

	int source, destination;
	for (int i=0; i<amount-1; i++){
			cin>>source>>destination;

			paths[source].push_back(destination);
			paths[destination].push_back(source);
	}

	searchForRestaurant(1, cats[1], maximum, amount);
	cout<<counter;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int counter=0;
vector<vector<int> > paths (100000);

void searchForRestaurant(int cats[], bool isVisited[], int source, int totalCats , int maximum, int amount){

	int counterForCats=0;
	if (totalCats>maximum){
		return;
	}
	bool isLeaf=true;
	isVisited[source]=true;
	for (int j=0; j<paths[source].size(); j++){
		if (isVisited[paths[source][j]]==false){
			if (cats[paths[source][j]]==1){
				counterForCats = totalCats+1;
			}
			else{
				counterForCats=0;
			}
			searchForRestaurant(cats, isVisited, j, counterForCats, maximum, amount);
			isLeaf=false;
		}

	}
	if (isLeaf){
		counter++;
	}
}

/*void initPaths(int amount){
	for (int i=1; i<=amount; i++){
		for (int j=1; j<=amount; j++){
			paths[i][j]=-1;
		}
	}
}*/

int main()
{
	int amount, maximum;
	cin>>amount>>maximum;
	int cats [amount+1];
	bool isVisited [amount+1];
	//initPaths(amount+1);

	for (int i=1; i<=amount; i++){
		cin>>cats[i];
		isVisited[i]=false;
	}

	for (int i=0; i<amount-1; i++){
			int source, destination;
			cin>>source>>destination;

			paths[source].push_back(destination);
			paths[destination].push_back(source);
	}

	searchForRestaurant(cats, isVisited, 1, cats[1], maximum, amount);
	cout<<counter;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
int counter=0;
int paths [1000][1000];

struct node {
	int number;
	int cat;
	bool isVisited=false;
};

void searchForRestaurant(int cats[], bool isVisited[], int source,int totalCats , int maximum, int amount){

	int counterForCats=0;
	if (totalCats>maximum){
		return;
	}
	bool isLeaf=true;
	isVisited[source]=true;
	for (int j=1; j<=amount; j++){
		if (paths[source][j]!=-1 && isVisited[paths[source][j]]==false){
			if (cats[paths[source][j]]==1){
				counterForCats = totalCats+1;

			}
			else{
				counterForCats=0;
			}
			searchForRestaurant(cats, isVisited, j, counterForCats, maximum, amount);
			isLeaf=false;
		}

	}
	if (isLeaf){
		counter++;
	}
}

void initPaths(int amount){
	for (int i=1; i<=amount; i++){
		for (int j=1; j<=amount; j++){
			paths[i][j]=-1;
		}
	}
}

int main()
{
	int amount, maximum;
	cin>>amount>>maximum;
	int cats [amount+1];
	bool isVisited [amount+1];
	initPaths(amount+1);

	for (int i=1; i<=amount; i++){
		cin>>cats[i];
		isVisited[i]=false;
	}

	for (int i=0; i<amount-1; i++){
			int source, destination;
			cin>>source>>destination;

			paths[source][destination] = destination;
			paths[destination][source] = source;
	}

	searchForRestaurant(cats, isVisited, 1, cats[0], maximum, amount);
	cout<<counter;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define MAX 100000
int counter=0;
vector<vector<int> > paths (MAX);

void searchForRestaurant(int cats[], bool isVisited[], int source, int totalCats , int maximum, int amount){

	int counterForCats=0;
	if (totalCats>maximum){
		return;
	}
	bool isLeaf=true;
	isVisited[source]=true;
	for (int j=0; j<paths[source].size(); j++){
		if (isVisited[paths[source][j]]==false){
			if (cats[paths[source][j]]==1){
				counterForCats = totalCats+1;
			}
			else{
				counterForCats=0;
			}
			searchForRestaurant(cats, isVisited, j, counterForCats, maximum, amount);
			isLeaf=false;
		}

	}
	if (isLeaf){
		counter++;
	}
}

/*void initPaths(int amount){
	for (int i=1; i<=amount; i++){
		for (int j=1; j<=amount; j++){
			paths[i][j]=-1;
		}
	}
}*/

int main()
{
	int amount, maximum;
	cin>>amount>>maximum;
	int cats [amount+1];
	bool isVisited [amount+1];
	//initPaths(amount+1);

	for (int i=1; i<=amount; i++){
		cin>>cats[i];
		isVisited[i]=false;
	}

	for (int i=0; i<amount-1; i++){
			int source, destination;
			cin>>source>>destination;

			paths[source].push_back(destination);
			paths[destination].push_back(source);
	}

	searchForRestaurant(cats, isVisited, 1, cats[1], maximum, amount);
	cout<<counter;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define MAX 10000
int counter=0;
int paths [MAX][MAX];

void searchForRestaurant(int cats[], bool isVisited[], int source, int totalCats , int maximum, int amount){

	int counterForCats=0;
	if (totalCats>maximum){
		return;
	}
	bool isLeaf=true;
	isVisited[source]=true;
	for (int j=1; j<=amount; j++){
		if (paths[source][j]!=-1 && isVisited[paths[source][j]]==false){
			if (cats[paths[source][j]]==1){
				counterForCats = totalCats+1;

			}
			else{
				counterForCats=0;
			}
			searchForRestaurant(cats, isVisited, j, counterForCats, maximum, amount);
			isLeaf=false;
		}

	}
	if (isLeaf){
		counter++;
	}
}

void initPaths(int amount){
	for (int i=1; i<=amount; i++){
		for (int j=1; j<=amount; j++){
			paths[i][j]=-1;
		}
	}
}

int main()
{
	int amount, maximum;
	cin>>amount>>maximum;
	int cats [amount+1];
	bool isVisited [amount+1];
	initPaths(amount+1);

	for (int i=1; i<=amount; i++){
		cin>>cats[i];
		isVisited[i]=false;
	}

	for (int i=0; i<amount-1; i++){
			int source, destination;
			cin>>source>>destination;

			paths[source][destination] = destination;
			paths[destination][source] = source;
	}

	searchForRestaurant(cats, isVisited, 1, cats[1], maximum, amount);
	cout<<counter;
    return 0;
}