#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int point[1000000];
int head[1000000];
int ver[1000000];
int nxt[1000000];
int cnt;
int out[1000000];
int in[1000000];
bool leaf[1000000];
int n;
int m;
int ans;
void add(int x,int y)
{
    nxt[++cnt] = head[x];
    head[x] = cnt;
    ver[cnt] = y;
}
void dfs(int now,int father,int already)
{
    if(leaf[now])
    {
        ans++;
        return;
    }
    for (int i = head[now]; i;i=nxt[i])
    {
        int v0 = ver[i];
        if(v0==father)
            continue;
        if(point[v0]==0)
            dfs(v0, now, 0);
        else
        {
            if(already+1<=m)
                dfs(v0, now, already + 1);
        }
    }
}
int main()
{
    scanf("%d%d", &n,&m);
    for (int i = 1; i <= n;i++)
        scanf("%d", &point[i]);
    for (int i = 1; i < n;i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        add(a, b);
        add(b, a);
        in[b]++;
        out[a]++;
    }
    for (int i = 2; i <= n;i++)
    {
        if(!out[i]||!in[i])
            leaf[i] = 1;
    }
    dfs(1,0,point[1]);
    printf("%d\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
vector <int> a[100005];
int p[100005],n,m,ans,f[100005];
void dfs(int jd,int lm){
	f[jd]=1;
	int ansf=1;
	if(p[jd])lm++;else lm=0;
	if(lm>m)return ;
	for(int i=0;i<a[jd].size();i++){
		if(f[a[jd][i]]==0){
			ansf=0;
			dfs(a[jd][i],lm);
		}
	}
	if(ansf){
		ans++;
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>p[i];
	int x,y;
	for(int i=1;i<n;i++){
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs(1,0);
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MX=100005;ll m,tot,in[MX],vis[MX],fir[MX],val[MX];struct STR{int next,to;}edge[MX<<1];
void add(int u,int v,int cnt){edge[cnt].to=v;edge[cnt].next=fir[u];fir[u]=cnt;}
void dfs(int x,ll now_cnt,ll _max){
	if(!(in[x]-1)){if(_max<=m)tot++;return;}
	if(_max>m)return;vis[x]=1;
	for(int i=fir[x];i;i=edge[i].next)
		if(!vis[edge[i].to]){
			ll q=val[edge[i].to]?now_cnt+1:0;dfs(edge[i].to,q,max(_max,q));
		}
}
int main(){
	ll n;scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)scanf("%lld",&val[i]);
	for(int i=1;i<=n-1;i++){int u,v;scanf("%d%d",&u,&v);add(u,v,i);add(v,u,i+n-1);in[u]++;in[v]++;}
	dfs(1,val[1],val[1]);printf("%lld",tot);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
int n;
void dfs(int m,int s){
    if(s>n) return;
    if(v[m].size()==0){
        judge[m]=1;
        return ;
    }
    for(int i=0;i<v[m].size();i++){
        if(a[v[m][i]]==1) dfs(v[m][i],s+1);
        else dfs(v[m][i],0);
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(x>y) swap(x,y);
        v[x].push_back(y);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
bool vis[200005];
int n;
void dfs(int m,int s){
    vis[m]=1;
    if(s>n) return;
    if(v[m].size()==1&&s<=n){
        judge[m]=1;
        return ;
    }
    for(int i=0;i<v[m].size();i++){
        if(vis[v[m][i]]==0){
            if(a[v[m][i]]==1) dfs(v[m][i],s+1);
            else dfs(v[m][i],0);
        }
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
bool vis[200005];
int n;
void dfs(int m,int s){
    if(s>n) return;
    vis[m]=1;
    if(v[m].size()==1&&s<=n){
        judge[m]=1;
        return ;
    }
    for(int i=0;i<v[m].size();i++){
        if(!vis[v[m][i]]){
            if(a[v[m][i]]==1) dfs(v[m][i],s+1);
            else dfs(v[m][i],0);
        }
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
int n;
void dfs(int m,int s){
    if(s>n) return;
    if(v[m].size()==0){
        judge[m]=1;
        return ;
    }
    if(n>=0){
        for(int i=0;i<v[m].size();i++){
            if(a[v[m][i]]==1) dfs(v[m][i],s+1);
            else dfs(v[m][i],0);
        }
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
int n;
void dfs(int m,int s){
    if(v[m].size()==0){
        judge[m]=1;
        return ;
    }
        if(s>n) return;
    if(n>=0){
        for(int i=0;i<v[m].size();i++){
            if(a[v[m][i]]==1) dfs(v[m][i],s+1);
            else dfs(v[m][i],0);
        }
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(x>y) swap(x,y);
        v[x].push_back(y);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
int n;
void dfs(int m,int s){
    if(s>n) return;
    if(v[m].size()==0&&s<=n){
        judge[m]=1;
        return ;
    }
    for(int i=0;i<v[m].size();i++){
        if(a[v[m][i]]==1) dfs(v[m][i],s+1);
        else dfs(v[m][i],0);
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(v[x].size()==0&&v[y].size()!=0) swap(x,y);
        else if(x>y) swap(x,y);
        v[x].push_back(y);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
int n;
void dfs(int m,int s){
    if(s>n) return;
    if(v[m].size()==0&&s<n){
        judge[m]=1;
        return ;
    }
    for(int i=0;i<v[m].size();i++){
        if(a[v[m][i]]==1) dfs(v[m][i],s+1);
        else dfs(v[m][i],0);
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(v[x].size()==0&&v[y].size()!=0) swap(x,y);
        else if(x>y) swap(x,y);
        v[x].push_back(y);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        if(judge[i]) ans++;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
int n;
void dfs(int m,int s){
    if(s>n) return;
    if(v[m].size()==0){
        judge[m]=1;
        return ;
    }
    if(n>=0){
        for(int i=0;i<v[m].size();i++){
            if(a[v[m][i]]==1) dfs(v[m][i],s+1);
            else dfs(v[m][i],0);
        }
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(x>y) swap(x,y);
        v[x].push_back(y);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
bool vis[200005];
int n;
void dfs(int m,int s){
    vis[m]=1;
    if(s>n) return;
    if(v[m].size()==1&&m!=1){
        judge[m]=1;
        return ;
    }
    for(int i=0;i<v[m].size();i++){
        if(vis[v[m][i]]==0){
            if(a[v[m][i]]==1) dfs(v[m][i],s+1);
            else dfs(v[m][i],0);
        }
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
int n;
void dfs(int m,int s){
    if(s>n) return;
    if(v[m].size()==0){
        judge[m]=1;
        return ;
    }
    for(int i=0;i<v[m].size();i++){
        if(a[v[m][i]]==1) dfs(v[m][i],s+1);
        else dfs(v[m][i],0);
    }
    return;
}
int main(){
    int m,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(v[x].size()==0&&v[y].size()!=0) swap(x,y);
        else if(x>y) swap(x,y);
        v[x].push_back(y);
    }
    dfs(1,a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';
    cout<<endl;*/
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v [200005];
int a[200005];
int judge[200005];
void dfs(int m,int n){
    if(v[m].size()==0){
        judge[m]=1;
        return ;
    }
    if(n>=0){
        for(int i=0;i<v[m].size();i++){
            dfs(v[m][i],n-a[i]);
        }
    }
    return;
}
int main(){
    int m,n,i,j,k;
    cin>>m>>n;
    for(i=1;i<=m;i++) cin>>a[i];
    for(i=1;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    dfs(1,n-a[1]);
    int ans=0;
    /*for(i=1;i<=m;i++) cout<<judge[i]<<' ';*/
    cout<<endl;
    for(i=1;i<=m;i++){
        ans+=judge[i];
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>v)
{
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
    if(mp[i].size()==0)
    {
        mx++;
        return;
    }

    for(long q=0;q<mp[i].size();q++)
    {

        // else cat++;
        fun(mp,cnt,mp[i][q],cat,m,n,v);
    }

}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     mp[q].push_back(w);

 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>v,vector<long long>&c)
{
    if(c[i]==1)
    {
 //       cout<<i<<"\n";

        return;}
    c[i]=1;
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
    if(mp[i].size()==1&&i>1)
    {
        mx++;
        return;
    }

    for(long q=0;q<mp[i].size();q++)
    {
        if(c[mp[i][q]]!=1)
        fun(mp,cnt,mp[i][q],cat,m,n,v,c);

    }
     c[i]=0;
}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 vector<long long>c(n+1,0);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     mp[q].push_back(w);
      mp[w].push_back(q);

 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v,c);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>v,vector<long long>&c)
{
    if(c[i]==1)
    {
        cout<<i<<"\n";

        return;}
    c[i]=1;
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
    if(mp[i].size()==1&&i>1)
    {
        mx++;
        return;
    }

    for(long q=0;q<mp[i].size();q++)
    {
        if(c[mp[i][q]]!=1)
        fun(mp,cnt,mp[i][q],cat,m,n,v,c);

    }
     c[i]=0;
}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 vector<long long>c(n+1,0);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     mp[q].push_back(w);
      mp[w].push_back(q);

 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v,c);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>v,vector<long long>&c)
{
    if(c[i]==1)
    {
 //       cout<<i<<"\n";

        return;}
    c[i]=1;
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
    if(mp[i].size()==1&&i>1)
    {
        mx++;
        return;
    }

    for(long q=0;q<mp[i].size();q++)
    {
        if(c[mp[i][q]]!=1)
        fun(mp,cnt,mp[i][q],cat,m,n,v,c);

    }
     c[i]=0;
}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 vector<long long>c(n+1,0);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     if(q!=w){
     mp[q].push_back(w);
      mp[w].push_back(q);
     }
 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v,c);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>&v,vector<long long>&c)
{
    if(c[i]==1)
    {
 //       cout<<i<<"\n";

        return;}
    c[i]=1;
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
   int z=0;

    for(long q=0;q<mp[i].size();q++)
    {
        if(c[mp[i][q]]!=1)
        {fun(mp,cnt,mp[i][q],cat,m,n,v,c);

            z++;
        }
    }
    if(z==0)
    {
        mx++;
        return;

    }
     c[i]=0;
}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 vector<long long>c(n+1,0);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     if(q!=w){
     mp[q].push_back(w);
      mp[w].push_back(q);
     }
 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v,c);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>&v,vector<long long>&c)
{
    if(c[i]==1)
    {
 //       cout<<i<<"\n";

        return;}
    c[i]=1;
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
   int z=0;

    for(long q=0;q<mp[i].size();q++)
    {
        if(c[mp[i][q]]!=1)
        {fun(mp,cnt,mp[i][q],cat,m,n,v,c);

            z++;
        }
    }
    if(z==0)
    {
        mx++;
        return;

    }
     //c[i]=0;
}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 vector<long long>c(n+1,0);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     if(q!=w){
     mp[q].push_back(w);
      mp[w].push_back(q);
     }
 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v,c);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>v)
{
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
    if(mp[i].size()==0&&i!=1)
    {
        mx++;
        return;
    }

    for(long q=0;q<mp[i].size();q++)
    {

        // else cat++;
        fun(mp,cnt,mp[i][q],cat,m,n,v);
    }

}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     mp[q].push_back(w);

 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>v,vector<long long>&c)
{
    if(c[i]==1)
    {
 //       cout<<i<<"\n";

        return;}
    c[i]=1;
   cat=cat+v[i];//<<"\n";
   if(v[i]==0)cat=0;
    if(cat>m)return;
    if(mp[i].size()==1&&i>1)
    {
        mx++;
        return;
    }

    for(long q=0;q<mp[i].size();q++)
    {
        if(c[mp[i][q]]!=1)
        fun(mp,cnt,mp[i][q],cat,m,n,v,c);

    }
     //c[i]=0;
}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 vector<long long>c(n+1,0);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     if(q!=w){
     mp[q].push_back(w);
      mp[w].push_back(q);
     }
 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v,c);
 cout<<mx;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long min(long long a,long long b)
{
    return a>b? b:a;
}
long long dp[100000];
long long mx=0;
void fun(map<long long,vector<long long>>&mp,long cnt,long i,long cat,long long m,long long n, vector<long long>v)
{

    if(cat>m&&i<=n/2)return;
    if(i>n/2)
    {
        mx++;
        return;
    }
    for(long q=0;q<mp[i].size();q++)
    {

        fun(mp,cnt,mp[i][q],cat+v[mp[i][q]],m,n,v);
    }

}
int main()
{

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 long long n,m;
 cin>>n>>m;
 vector<long long>v(n+1);
 for(long i=1;i<=n;i++)
 {
     cin>>v[i];
 }
 map<long long,vector<long long>>mp;
 mp[0LL].push_back(1);
 for(long long i=0;i<n-1;i++)
 {
     long long q,w;
     cin>>q>>w;
     mp[q].push_back(w);

 }
 long cnt=0;

 fun(mp,cnt,0,0,m,n,v);
 cout<<mx;

 return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;

void dfs( int x , int con ) {
/*	cout << x + 1 << endl;
	cout << con << " " << cat[x] << endl;*/
	for (int i = 0; i < v[x].size(); i++) {
		dfs( v[x][i] , ( cat[x] == 1 ? con + 1 : 0 ) );
	}

	if (v[x].size() == 0) {
		if (con + cat[x] <= m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , 0);
	printf("%d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;
int bio[100001];

void dfs( int x , int con ) {
	if (bio[x] == 1) { return; }
	bio[x] = 1;
/*	cout << x + 1 << endl;
	cout << con << " " << cat[x] << endl;*/
	for (int i = 0; i < v[x].size(); i++) {
		dfs( v[x][i] , ( cat[x] == 1 ? con + 1 : 0 ) );
	}
//	cout << v[x].size() << endl;
	if (v[x].size() == 1 && x > 1) {
		if (con + cat[x] <= m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , 0);
	printf("%d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int n , d;
int cat[100002];
vector < int > v[100002];
int out = 0;

int dfs( int node , int par , int cats , int ma ) {
	if ( cats > d ) {
		ma = 1;
	}
//	cout << node << " " << par << " " << cats << " " << ma << " " << cat[node] << endl;
	for ( int i = 0; i < v[node].size(); i++ ) {
		if ( v[node][i] != par ) {
			dfs( v[node][i] , node , ( cat[v[node][i]] == 1 ? cats + 1 : 0) , ma);
		}
	}

	if ( v[node].size() == 1 && node != 0 ) {
		if ( ma == 0 ) {
			out++;
		}
	}

}

int main() {
	scanf("%d%d" , &n , &d);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , -1 , cat[0] , 0 );
	printf("%d\n" , out );
return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;
int bio[100001];

void dfs( int x , int con ) {
	if (bio[x] == 1) { return; }
	bio[x] = 1;
/*	cout << x + 1 << endl;
	cout << con << " " << cat[x] << endl;*/
	for (int i = 0; i < v[x].size(); i++) {
		dfs( v[x][i] , ( cat[x] == 1 ? con + 1 : 0 ) );
	}
//	cout << v[x].size() << endl;
	if (v[x].size() == 1 && x > 0) {
		if (con + cat[x] <= m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , 0);
	printf("%d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;

void dfs( int x , int con ) {
/*	cout << x + 1 << endl;
	cout << con << " " << cat[x] << endl;*/
	for (int i = 0; i < v[x].size(); i++) {
		dfs( v[x][i] , ( cat[x] == 1 ? con + 1 : 0 ) );
	}

	if (v[x].size() == 0) {
		if (con + cat[x] < m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , 0);
	printf("%d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;

void dfs( int x , int tr ) {

//	cout << tr << " " << cat[x] << endl;
	for (int i = 0; i < v[x].size(); i++) {
		dfs( v[x][i] , tr + cat[x] );
	}
	if (v[x].size() == 0) {
		if (tr + cat[x] <= m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , 0 );
	printf("%d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;

vector < pair < long long int , long long int > > v;
queue < pair < long long int , long long int > > q;
int main() {

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

	int x , y;
	for (int i = 0; i < n; i++) {
		scanf("%d%d" , &x , &y);
		v.push_back( make_pair( x , y ) );
	}

	sort( v.begin() , v.end() );

	q.push( v[0] );
	long long int prx = q.front().first , pry = q.front().second;
	long long int out = 0 , tr = v[0].second;
	out = max( out , tr );
	for (int i = 1; i < n; i++) {
		while ( prx + d <= v[i].first ) {
			tr -= pry;
			q.pop();
//			cout << "fas" << endl;
//			cout << tr << endl;
//			cout << "fap" << endl;
			if (q.empty()) {break;}
			prx = q.front().first;
			pry = q.front().second;
		}
//		cout << tr << endl;
		q.push( v[i] );
		tr += v[i].second;
		out = max( out , tr );
		prx = q.front().first;
		pry = q.front().second;
//		cout << tr << endl;
//		cout << "---" << endl;
	}

	printf("%I64d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;
int bio[100001];

void dfs( int x , int con ) {
	if ( bio[x] == 1 ) { return; }
	bio[x] = 1;
/*	cout << x + 1 << endl;
	cout << con << " " << cat[x] << endl;*/
	for (int i = 0; i < v[x].size(); i++) {
		dfs( v[x][i] , ( cat[x] == 1 ? con + 1 : 0 ) );
	}

	if (v[x].size() == 0) {
		if (con + cat[x] <= m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , 0);
	printf("%d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;
int bio[100001];

void dfs( int x , int con , int par) {
/*	cout << x + 1 << endl;
	cout << con << " " << cat[x] << endl;*/
	for (int i = 0; i < v[x].size(); i++) {
		if (v[x][i] != par ) { dfs( v[x][i] , ( cat[x] == 1 ? con + 1 : 0 ) , x ); }
	}
//	cout << v[x].size() << endl;
	if (v[x].size() == 1 && x > 0) {
		if (con + cat[x] <= m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

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

	dfs( 0 , 0 , -1);
	printf("%d\n" , out);

return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > v[100001];
int cat[100001];
int out = 0;
int n , m;
int bio[100001];

void dfs( int x , int con ) {
/*	cout << x + 1 << endl;
	cout << con << " " << cat[x] << endl;*/
	for (int i = 0; i < v[x].size(); i++) {
		dfs( v[x][i] , ( cat[x] == 1 ? con + 1 : 0 ) );
	}

	if (v[x].size() == 0) {
		if (con + cat[x] <= m) {out++;}
	}
//	cout << out << endl;
}

int main() {

	int x , y;
	scanf("%d%d" , &n , &m);
	for (int i = 0; i < n; i++)	{
		scanf("%d" , &x);
		cat[i] = x;
	}

	for ( int i = 0; i < n - 1; i++ ) {
		scanf("%d%d" , &x , &y);
		x--;
		y--;
		if ( x > y ) {swap(x , y);}
		v[x].push_back( y );
	}

	dfs( 0 , 0);
	printf("%d\n" , out);

return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int k)
{
  vis[k]=1;
  s.push(k);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
        if(dis[adj[v][j]]==1 && dis[v]!=0)
        {
           //cout<<adj[v][j]<<"\n";
           dis[adj[v][j]]+=dis[v];
        }
        //cout<<adj[v][j]<<"\n";
        if(adj[adj[v][j]].size()==1)
        {
            if(dis[adj[v][j]]==0)
                dis[adj[v][j]]=dis[v];
        }
        if(adj[adj[v][j]].size()==1 && dis[adj[v][j]]<=m)
        {

                //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
                c1++;
        }
        dfs(adj[v][j]);
        //if(dis[adj[v][j]]<=m && adj[adj[v][j]].size()==0)
        //c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>a;
    dis[i]=a;
  }
  for(i=1;i<=n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int i)
{
  vis[i]=1;
  s.push(i);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        if(dis[adj[v][j]]==1 && dis[v]==1)
        {
          dis[adj[v][j]]+=dis[v];
        }
        dfs(adj[v][j]);
        if(dis[adj[v][j]]<=m)
        c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
    cin>>a;
    dis[i+1]=a;
  }
  for(i=1;i<=n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int k)
{
  vis[k]=1;
  s.push(k);
  if(c1>m)
  return;
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
        if(dis[adj[v][j]]!=0 && dis[v]!=0)
        {
           //cout<<adj[v][j]<<"\n";
           dis[adj[v][j]]+=dis[v];
        }
        //cout<<adj[v][j]<<"\n";
        if(adj[adj[v][j]].size()==1)
        {
            if(dis[adj[v][j]]==0)
                dis[adj[v][j]]=dis[v];
        }
        if(adj[adj[v][j]].size()==1 && dis[adj[v][j]]<=m)
        {

                //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
                c1++;
        }
        dfs(adj[v][j]);
        //if(dis[adj[v][j]]<=m && adj[adj[v][j]].size()==0)
        //c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>a;
    dis[i]=a;
  }
  for(i=1;i<=n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int k)
{
  vis[k]=1;
  s.push(k);
  if(c1>m)
  return c1;
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
        if(dis[adj[v][j]]!=0 && dis[v]!=0)
        {
           //cout<<adj[v][j]<<"\n";
           dis[adj[v][j]]+=dis[v];
        }
        //cout<<adj[v][j]<<"\n";
        if(adj[adj[v][j]].size()==1)
        {
            if(dis[adj[v][j]]==0)
                dis[adj[v][j]]=dis[v];
        }
        if(adj[adj[v][j]].size()==1 && dis[adj[v][j]]<=m)
        {

                //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
                c1++;
        }
        dfs(adj[v][j]);
        //if(dis[adj[v][j]]<=m && adj[adj[v][j]].size()==0)
        //c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>a;
    dis[i]=a;
  }
  for(i=1;i<=n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<int> adj[100001];
stack<int> s;
bool vis[100001]={0};
int dis[100001]={0};

int dfs(int i)
{
  vis[i]=1;
  s.push(i);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        if(dis[adj[v][i]]==1 && dis[v]==1)
        {
          dis[adj[v][i]]+=dis[v];
        }
        dfs(adj[v][i]);
        if(dis[adj[v][i]]<=m)
        c1++;
      }
    }
  }
  return c1;
}

int main()
{
  int n,i,a,x,y;
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
    cin>>a;
    dis[i+1]=a;
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int k)
{
  vis[k]=1;
  s.push(k);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
        if(dis[adj[v][j]]!=0 && dis[v]!=0)
        {
           //cout<<adj[v][j]<<"\n";
           dis[adj[v][j]]+=dis[v];
        }
        //cout<<adj[v][j]<<"\n";
        if(adj[adj[v][j]].size()==1)
        {
            if(dis[adj[v][j]]==0)
                dis[adj[v][j]]=dis[v];
        }
        if(adj[adj[v][j]].size()==1 && dis[adj[v][j]]<=m)
        {

                //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
                c1++;
        }
        dfs(adj[v][j]);
        //if(dis[adj[v][j]]<=m && adj[adj[v][j]].size()==0)
        //c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>a;
    dis[i]=a;
  }
  for(i=1;i<=n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int i)
{
  vis[i]=1;
  s.push(i);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        if(dis[adj[v][i]]==1 && dis[v]==1)
        {
          dis[adj[v][i]]+=dis[v];
        }
        dfs(adj[v][i]);
        if(dis[adj[v][i]]<=m)
        c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
    cin>>a;
    dis[i+1]=a;
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll N=1e5+5;
vector<ll> adj[N];
bool vis[N]={0};
set<ll> s;
stack<ll> st;
ll arr[N]={0},dis[N]={0},m,n,c=0;

ll dfs(ll k)
{
  vis[k]=1;
    for(int i=0;i<adj[k].size();i++)
    {
     if(adj[k].size()==1 && k!=1)
     {
      if(*(--s.end())<=m)
      c++;
      //cout<<c<<endl;
      s.erase(--s.end());
     }
    if(vis[adj[k][i]]==0)
    {
      if(arr[adj[k][i]]==1)
      {
        if(arr[k]==1)
        dis[adj[k][i]]=dis[k]+1;
        else
        dis[adj[k][i]]=1;
      }
      else
      dis[adj[k][i]]=dis[k];
      s.insert(dis[adj[k][i]]);
      dfs(adj[k][i]);
      //cout<<dis[adj[k][i]]<<" ";
    }
    //s.insert(dis[adj[k][i]]);
   }
   return c;
 }

int main()
{
  ll x,y,i;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>arr[i];
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if(arr[1]==1)
  dis[1]=1;
  ll c1 = dfs(1);
  cout<<c1<<endl;
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll N=1e5+5;
vector<ll> adj[N];
bool vis[N]={0};
set<ll> s;
stack<ll> st;
ll arr[N]={0},dis[N]={0},m,n,c=0;

ll dfs(ll k)
{
  vis[k]=1;
    for(int i=0;i<adj[k].size();i++)
    {
     if(adj[k].size()==1)
     {
      if(*(--s.end())<=m)
      c++;
      cout<<c<<endl;
      s.erase(--s.end());
     }
    if(vis[adj[k][i]]==0)
    {
      if(arr[adj[k][i]]==1)
      {
        if(arr[k]==1)
        dis[adj[k][i]]=dis[k]+1;
        else
        dis[adj[k][i]]=dis[k];
      }
      else
      dis[adj[k][i]]=dis[k];
      s.insert(dis[adj[k][i]]);
      dfs(adj[k][i]);
      //cout<<dis[adj[k][i]]<<" ";
    }
    //s.insert(dis[adj[k][i]]);
   }
 }

int main()
{
  ll x,y,i;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>arr[i];
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if(arr[1]==1)
  dis[1]=1;
  ll c1 = dfs(1);
  cout<<c1<<endl;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

int c1=0,c=0,m;
vector<int> adj[100001];
stack<int> s;
bool vis[100001]={0};
int dis[100001]={0};

int dfs(int i)
{
  vis[i]=1;
  s.push(i);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        if(dis[adj[v][i]]==1 && dis[v]==1)
        {
          dis[adj[v][i]]+=dis[v];
        }
        dfs(adj[v][i]);
        if(dis[adj[v][i]]<=m)
        c1++;
      }
    }
  }
  return c1;
}

int main()
{
  int n,i,a,x,y;
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
    cin>>a;
    dis[i+1]=a;
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int k)
{
  vis[k]=1;
  s.push(k);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
        if(dis[adj[v][j]]==1 && dis[v]==1)
        {
           dis[adj[v][j]]+=dis[v];
        }
        //cout<<adj[v][j]<<c<<"\n";
        if(adj[adj[v][j]].size()==0)
        {
            if(dis[adj[v][j]]==0)
                dis[adj[v][j]]=dis[v];
        }
        if(adj[adj[v][j]].size()==0 && dis[adj[v][j]]<=m)
        {

                //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
                c1++;
        }
        dfs(adj[v][j]);
        //if(dis[adj[v][j]]<=m && adj[adj[v][j]].size()==0)
        //c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
    cin>>a;
    dis[i+1]=a;
  }
  for(i=1;i<=n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    //adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll N=1e5+5;
vector<ll> adj[N];
bool vis[N]={0};
set<ll> s;
stack<ll> st;
ll arr[N]={0},dis[N]={0},m,n,c=0;

ll dfs(ll k)
{
  vis[k]=1;
    for(int i=0;i<adj[k].size();i++)
    {
     if(adj[k].size()==1 && k!=1)
     {
      if(*(--s.end())<=m)
      c++;
      //cout<<c<<endl;
      s.erase(--s.end());
     }
    if(vis[adj[k][i]]==0)
    {
      if(arr[adj[k][i]]==1)
      {
        if(arr[k]==1)
        dis[adj[k][i]]=dis[k]+1;
        else
        dis[adj[k][i]]=dis[k];
      }
      else
      dis[adj[k][i]]=dis[k];
      s.insert(dis[adj[k][i]]);
      dfs(adj[k][i]);
      //cout<<dis[adj[k][i]]<<" ";
    }
    //s.insert(dis[adj[k][i]]);
   }
   return c;
 }

int main()
{
  ll x,y,i;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>arr[i];
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if(arr[1]==1)
  dis[1]=1;
  ll c1 = dfs(1);
  cout<<c1<<endl;
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll N = 1e5+5;
bool vis[N]={0};
vector<ll> adj[N];
ll arr[N]={0},ans=0,m,n;

void dfs(ll k,ll c)
{
  vis[k]=1;
  if(arr[k]==1)
  {
    c++;
    if(c>m)
    return;
  }
  else
  c=0;
  if(adj[k].size()==1 && k!=1)
  {
    ans++;
  }
  for(int i=0;i<adj[k].size();i++)
  {
    if(vis[adj[k][i]]==0)
    {
     dfs(adj[k][i],c);
    }
  }
 }

int main()
{
  ll x,y,i,c;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>arr[i];
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1,c);
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll N = 1e5+5;
bool vis[N]={0};
vector<ll> adj[N];
ll arr[N]={0},ans=0,m,n;

void dfs(ll k,ll c)
{
  vis[k]=1;
  if(arr[k]==1)
  {
    c++;
    if(c>m)
    return;
  }
  else
  c=0;
  if(adj[k].size()==1 && k!=1)
  {
    ans++;
  }
  for(int i=0;i<adj[k].size();i++)
  {
    if(vis[adj[k][i]]==0)
    {
     dfs(adj[k][i],c);
    }
  }
 }

int main()
{
  ll x,y,i,c=0;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>arr[i];
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1,c);
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll N=1e5+5;
vector<ll> adj[N];
bool vis[N]={0};
set<ll> s;
stack<ll> st;
ll arr[N]={0},dis[N]={0},m,n,c=0;

ll dfs(ll k)
{
  vis[k]=1;
    for(int i=0;i<adj[k].size();i++)
    {
     if(adj[k].size()==1)
     {
      if(*(--s.end())<=m)
      c++;
      //cout<<c<<endl;
      s.erase(--s.end());
     }
    if(vis[adj[k][i]]==0)
    {
      if(arr[adj[k][i]]==1)
      {
        if(arr[k]==1)
        dis[adj[k][i]]=dis[k]+1;
        else
        dis[adj[k][i]]=dis[k];
      }
      else
      dis[adj[k][i]]=dis[k];
      s.insert(dis[adj[k][i]]);
      dfs(adj[k][i]);
      //cout<<dis[adj[k][i]]<<" ";
    }
    //s.insert(dis[adj[k][i]]);
   }
   return c;
 }

int main()
{
  ll x,y,i;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>arr[i];
  }
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if(arr[1]==1)
  dis[1]=1;
  ll c1 = dfs(1);
  cout<<c1<<endl;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

long int c1=0,c=0,m;
vector<long int> adj[100001];
stack<long int> s;
bool vis[100001]={0};
long int dis[100001]={0};

long int dfs(long int k)
{
  vis[k]=1;
  s.push(k);
  while(!s.empty())
  {
    long int v=s.top();
    s.pop();
    for(int j=0;j<adj[v].size();j++)
    {
      if(vis[adj[v][j]]==0)
      {
        //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
        if(dis[adj[v][j]]!=0 && dis[v]!=0)
        {
           //cout<<adj[v][j]<<"\n";
           dis[adj[v][j]]=dis[v]+1;
        }
        //cout<<adj[v][j]<<"\n";
        if(adj[adj[v][j]].size()==1)
        {
            if(dis[adj[v][j]]==0)
                dis[adj[v][j]]=dis[v];
        }
        if(adj[adj[v][j]].size()==1 && dis[adj[v][j]]<=m)
        {

                //cout<<adj[v][j]<<dis[adj[v][j]]<<"\n";
                c1++;
        }
        dfs(adj[v][j]);
        //if(dis[adj[v][j]]<=m && adj[adj[v][j]].size()==0)
        //c1++;
      }
    }
  }
  return c1;
}

int main()
{
  long int n,i,a,x,y;
  cin>>n>>m;
  for(i=1;i<=n;i++)
  {
    cin>>a;
    dis[i]=a;
  }
  for(i=1;i<=n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout<<dfs(1)<<"\n";
  return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
#define int long long
int n,m;
int v[10010];
#define maxn 10010
int head[maxn],to[maxn<<1],nxt[maxn<<1];
int tot=0;
int lef[maxn],cnt=0;
void add(int x,int y)
{
    to[++tot] = y;
    nxt[tot] = head[x];
    head[x]=tot;
}
int fa[maxn];
void dfs(int x,int f)
{
    fa[x] = f;
    bool in =0;
    for(int i=head[x];i;i=nxt[i])
    {
        int y=to[i];
        if(y==f) continue;
        in=1;
        dfs(y,x);
    }
    if(!in) lef[++cnt] = x;
}
int tp(int x)
{
    int sum=0;
    int ret=0;
    while(x)
    {
        ret=max(ret,sum);
        if(!v[x]) sum=0;
        else sum++;
        ret=max(ret,sum);
        x=fa[x];
    }
    return ret;
}
signed main()
{
    scanf("%lld",&n,&m);
    for(int i=1;i<=n;i++)
    scanf("%lld",&v[i]);
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%lld",&x,&y);
        add(x,y);
        add(y,x);
    }
    int ans = 0;
    dfs(1,0);
    for(int i=1;i<=cnt;i++)
    {
        int sr = tp(lef[i]);
        if(sr<=m) ans++;
    }
    printf("%lld",ans);
}


 #include <bits/stdc++.h>
    using namespace std;
    #define loop(n)  for(int i=0;i<n;i++)
    #define endl '\n'
    #define MAXNODES 1000000+9
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<pair<int,int> >vp;
    using namespace std;
    struct point {
	double x, y;
    };
int ans;
vector<vi> edges(MAXNODES),emptyEdges(MAXNODES);
bool visited[MAXNODES];
bool state  [MAXNODES];
void dfs(int node,int rem,int m)
{
   visited[node] = 1;
   if(edges[node].size()==1&&node!=1&&rem<=m)
   {
       ans++;
       return;
   }
   for(int neighbor : edges[node])
        if(!visited[neighbor])
        {
            if(state[neighbor]+rem <= m)
            dfs(neighbor,(state[neighbor]==1)?rem+1:0,m);
        }
}

    int main()
    {
        cin.tie(0);
        cin.sync_with_stdio(0);
        cout.tie(0);
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            cin>>state[i];
        }
        loop(n-1)
        {
            int a,b;
            cin>>a>>b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        dfs(1,state[1],m);
        cout<<ans;

    }


#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1000;
struct Node
{
	int v, next;
}p[maxn*2];
int head[maxn], cnt, a[maxn],n,m,ans;
void add(int u, int v)
{
	p[++cnt].v = v;
	p[cnt].next = head[u];
	head[u] = cnt;
}
void DFS(int u,int f,int w)
{
	bool flag =0;
	for (int i = head[u]; i; i = p[i].next)
	{
		int v = p[i].v;
		if (v == f)
		{
			continue;
		}
		flag = 1;
		if (a[v] + w > m)
		{
			continue;
		}
		if (a[v])
		{
			DFS(v, u, a[v] + w);
		}
		else
		{
			DFS(v, u, 0);
		}
	}
	if (!flag)
	{
		ans++;
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for (int i = 1; i <= n-1; i++)
	{
		int a, b;
		cin >> a>>b;
		add(a, b);
		add(b, a);
	}
	DFS(1, 0, a[1]);
	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e5+5;
int n,m,ans;
int mark[M],dis[M],dep[M];
vector<int>Edge[M];

void dfs(int x, int fa, int d){
	if(mark[x]) d++;
	else d=0;
	if(d>m) return;
	int SIZE=Edge[x].size();
	if(x!=1 && SIZE==1) ans++;
	for(int i=0,_i=Edge[x].size(); i<_i; i++){
		int y=Edge[x][i];
		if(y==fa) continue;
		dfs(y,x,d);
	}
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++)
		scanf("%d",&mark[i]);
	for(int i=1,a,b; i<n; i++){
		scanf("%d %d",&a,&b);
		Edge[a].push_back(b);
		Edge[b].push_back(a);
	}
	dfs(1,0,0);
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 10010
int lef[maxn];
int cnt=0;
int fa[maxn];
int head[maxn],to[maxn<<1],nxt[maxn<<1];
int n;
int v[maxn];
int tot=0;
void add(int x,int y)
{
    to[++tot] = y;
    nxt[tot] = head[x];
    head[x] = tot;
}
void dfs1(int x,int f)
{
    fa[x] = f;
    bool in = 0;
    for(int i=head[x];i;i=nxt[i])
    {
        int y= to[i];
        if(y==f) continue;
        in=1;
        dfs1(y,x);
    }
    if(in==0) lef[++cnt] = x;
}
int huisu(int x)
{
   int ret=0,sum=0;
   while(x)
   {
       ret=max(sum,ret);
       if(v[x]) sum++;
       else sum=0;
       ret=max(sum,ret);
       x=fa[x];
   }
   return ret;
}
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    scanf("%d",&v[i]);
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        add(x,y);
        add(y,x);
    }
    dfs1(1,0);
    int ans=0;
    for(int i=1;i<=cnt;i++)
    {
        int sr = huisu(lef[i]);
      //  printf("%d %d\n",lef[i],sr);

        if(sr<=m)
        ans++;
    }
    printf("%d",ans);
}


#include <bits/stdc++.h>
#define il inline
#define re register
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
/*struct edge{
	int u, v;
	int next;
}e[maxn<<1];
int p[maxn], eid;
il void add(int u, int v) {
	e[++eid].u = u;
	e[eid].v = v;
	e[eid].next = p[u];
	p[u] = eid;
}*/
int n, m, ans;
int a[maxn];
vector<int> e[maxn];
il void dfs(int u, int fa, int cnt) {
	if(e[u].size() == 1&&cnt <= m) {
		ans++;
		return ;
	}
	for(re int i = 0; i < e[u].size(); ++i) {
		int v = e[u][i];
		if(v == fa) continue;
		if(a[v] == 1&&cnt+1 > m) continue;
		if(a[v] == 0) dfs(v, u, 0);
		else dfs(v, u, cnt+1);
	}
	return ;
}
int main() {
	scanf("%d%d", &n, &m);
	for(re int i = 1; i <= n; ++i) scanf("%d", a+i);
	int u, v;
	for(re int i = 1; i < n; ++i) {
		scanf("%d%d", &u, &v);
		//add(u, v); add(v, u);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	ans = 0;
	dfs(1, 0, a[1]);
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, k;
int color[maxn];
vector<int> e[maxn];
int ans = 0;
void dfs(int u, int fa, int one, int fg){
	if(one == k + 1)fg = 1;
	if(e[u].size() == 1 && e[u][0] == fa){
		if(!fg)ans++;
		return;
	}
	for(register int i = 0; i < (int)e[u].size(); i ++){
		int v = e[u][i];
		if(v == fa)continue;
		if(color[v])dfs(v, u, one + 1, fg);
		else dfs(v, u, 0, fg);
	}
}
int main(){
	scanf("%d%d", &n, &k);
	for(register int i = 1; i <= n; i ++){
		scanf("%d", &color[i]);
	}
	for(register int i = 1; i < n; i ++){
		int u, v;
		scanf("%d%d", &u, &v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1, 1, color[1], 0);
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;

int p[100005];
struct node{
	int next,to;
}a[200005];
int head[10005];
int c[100005];
int top,n,m;

void add(int u,int v){
	a[++top].next=head[u];
	a[top].to=v;
	head[u]=top;
}

int ans;

void dfs(int u,int fa,int now){
	for (int i=head[u];i;i=a[i].next){
		int v=a[i].to;
		if (v==fa)
			continue;
		if (p[v]+now>m)
			continue;
		if (c[v]==1)
			if (now+p[v]<=m)
				ans++;
		if (now>0&&p[v])
			dfs(v,u,now+p[v]);
		if (now>0&&(!p[v]))
			dfs(v,u,0);
	}
	return;
}

int main(){
	//freopen (".in","r",stdin);
	//freopen (".out","w",stdout);
	scanf ("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf ("%d",p+i);
	int u,v;
	for (int i=1;i<n;i++){
		scanf ("%d%d",&u,&v);
		add(u,v);
		add(v,u);
		c[u]++;
		c[v]++;
	}
	dfs(1,0,p[1]);
	printf ("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define il inline
#define re register
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
/*struct edge{
	int u, v;
	int next;
}e[maxn<<1];
int p[maxn], eid;
il void add(int u, int v) {
	e[++eid].u = u;
	e[eid].v = v;
	e[eid].next = p[u];
	p[u] = eid;
}*/
int n, m, ans;
int a[maxn];
vector<int> e[maxn];
il void dfs(int u, int fa, int cnt) {
	for(re int i = 0; i < e[u].size(); ++i) {
		int v = e[u][i];
		if(v == fa) continue;
		if(cnt+1 > m) continue;
		if(a[v] == 0) dfs(v, u, 0);
		else dfs(v, u, cnt+1);
	}
	if(e[u].size() == 1&&cnt <= m)
		ans++;
	return ;
}
int main() {
	scanf("%d%d", &n, &m);
	for(re int i = 1; i <= n; ++i) scanf("%d", a+i);
	int u, v;
	for(re int i = 1; i < n; ++i) {
		scanf("%d%d", &u, &v);
		//add(u, v); add(v, u);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	ans = 0;
	dfs(1, 0, a[1]);
	printf("%d\n", ans);
	return 0;
}


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

struct Solution{
    int n, m, ans;
    vector<vector<int> > e;
    vector<int> maxn, up, v;

    void dfs(int x, int fa){
        up[x] = 0;
        if(v[x] == 1){
            up[x] = up[fa] + 1;
        }
        maxn[x] = max(maxn[fa], up[x]);
        for(int i = 0; i < e[x].size(); i++){
            int y = e[x][i];
            if(y == fa) continue;
            dfs(y, x);
        }
        if(e[x].size() == 1 && x != 1){
            if(maxn[x] <= m) ans++;
        }
    }

    void Solve(){
        scanf("%d%d", &n, &m);
        ans = 0;
        maxn.resize(n + 1);
        up.resize(n + 1);
        v.resize(n + 1);
        e.resize(n + 1);
        for(int i = 1; i <= n; i++){
            scanf("%d", &v[i]);
        }
        for(int i = 1; i <= n - 1; i++){
            int x, y;
            scanf("%d%d", &x, &y);
            e[x].push_back(y);
            e[y].push_back(x);
        }
        dfs(1, 0);
        printf("%d\n", ans);
    }
};

int main(){
    Solution().Solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,m;
int a[N];
int u,v;
int tot,deg[N],head[N],nxt[N<<1],ver[N<<1];
int ans;
inline void add(int x,int y)
{
	ver[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
	++deg[y];
}
inline void dfs(int p,int fa,int maxsum,int las)
{
	if(maxsum>m) return ;
	if(deg[p]==1&&p!=1)
	{
		if(maxsum<=m) ++ans;
		return ;
	}
	for(int i=head[p];i;i=nxt[i])
	{
		int to=ver[i];
		if(to==fa) continue;
		if(a[to]) dfs(to,p,max(maxsum,las+1),las+1);
		else dfs(to,p,maxsum,0);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v),add(v,u);
	}
	dfs(1,0,a[1],a[1]);
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>

#define NN 100005

using namespace std;

int cats[NN];

vector<int> ne[NN];

int ans=0,m;

void dfs(int u,int father,int c){

	if(cats[u]) c++;

	else c=0;

	if(c>m) return;

	int child=0;

	for (int i=0;i<ne[u].size();i++){

		if (ne[u][i]==father) continue;

		child++;

		dfs(ne[u][i],u,c);

	}

	if (!child){

		ans++;

		return;

	}

}

int main(){

	//freopen ("in.in","r",stdin);

	//freopen ("out.out","w",stdout);

	int n,u,v;

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

	for (int i=1;i<=n;i++) scanf("%d",&cats[i]);

	for (int i=0;i<n-1;i++){

		scanf("%d%d",&u,&v);

		ne[u].push_back(v);

		ne[v].push_back(u);

	}

	dfs(1,0,0);

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

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define NN 11111
vector<int> ne[NN];
int ans,c[NN],vst[NN];
int cnt[NN];
int n,m;

void dfs(int u,int fa){
	if(vst[u]==1) cnt[u]=cnt[fa]+1;
	else cnt[u]=0;
	if(cnt[u]>m) return ;
	if(ne[u].size()==1) ans++;
	for (int i=0;i<ne[u].size();i++){
		int v=ne[u][i];
		if(v==fa) continue;
		dfs(v,u);
	}
}

int main(){
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%d",&vst[i]);
	}

	int mm=n-1;
	while(mm--){
		int u,v;
		scanf("%d%d",&u,&v);
		ne[u].push_back(v);
		ne[v].push_back(u);
	}

	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}


import java.io.*;
import java.util.*;
import java.math.*;

public class code{

	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		//Writer wr=new Writer(System.out);

		int ans=0;
		int t1=0;
		int t2=0;
		int t3=0;
		int n=sc.nextInt();
		for(int i=2;i<=n/2;i++){

			t1=n/i;
			t2=(t1*(t1+1))/2;
			t2--;
			ans+=t2;
		}
		ans*=4;
		System.out.print(ans+" ");

	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Q4 {
    public static long mod = (long) 1e18 + 11;

    public static void main(String[] args) {
//        System.out.println(mod);
        InputReader s = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;
//        t = s.nextInt();
        nexttest:
        while (t-- > 0) {
            int n = s.nextInt();

            int[] p = createSets(n + 1);
            for (int i = 2; i <= n; i++) {
                for (int j = i; j <= n; j += i) {
                    unite(p, i, j);
                }
            }
            long[] ans = new long[n + 1];
            for (int i = 2; i <= n; i++) {
                for (int j = 2 * i; j <= n; j += i) {
                    ans[root(p, i)] += j / i;
                }
            }
            long max = 0;
            for (int i = 0; i < n + 1; i++)
                max = Math.max(max, ans[i]);
            out.println(max * 4);
        }

        out.close();
    }

    public static int[] createSets(int size) {
        int[] p = new int[size];
        for (int i = 0; i < size; i++) {
            p[i] = i;
        }
        return p;
    }

    public static int root(int[] p, int x) {
        return x == p[x] ? x : (p[x] = root(p, p[x]));
    }

    public static void unite(int[] p, int a, int b) {
        a = root(p, a);
        b = root(p, b);
        if (a != b) {
            p[a] = b;
        }
    }

    public static void printArray(int[] a, PrintWriter out) {
        for (int i = 0; i < a.length; i++) {
            out.print(a[i]);
            out.print(' ');
        }
        out.println();
    }

    public static long pow(long x, long n, long mod) {
        long res = 1;
        for (long p = x; n > 0; n >>= 1, p = (p * p) % mod) {
            if ((n & 1) != 0) {
                res = (res * p % mod);
            }
        }
        return res;
    }

    static long gcd(long n1, long n2) {
        long r;
        while (n2 != 0) {
            r = n1 % n2;
            n1 = n2;
            n2 = r;
        }
        return n1;
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.util.*;

import java.io.*;

public class Main{

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();

          }

    static class Solver {

        class Node implements Comparable<Node>{
            int i;
            int p;

            Node(int i,int p)
            {
                this.i=i;
                this.p=p;

            }

           public int compareTo(Node n)
            {
                return Integer.compare(this.p, n.p);
            }
        }

        public boolean done(int[] sp,int[] par)
        {
            int root;

            root=findSet(sp[0],par);

           for(int i=1;i<sp.length;i++)
           {
                if(root!=findSet(sp[i], par))
                    return false;
           }
           return true;
        }
       public int findSet(int i,int[] par)
       {
           int x =i;
            boolean flag =false;
            while(par[i]>=0)
            {
                flag = true;
                i=par[i];
            }
            if(flag)
                par[x]=i;
            return i;
       }

       public void unionSet(int i,int j,int[] par)
       {
            int x = findSet(i, par);
            int y = findSet(j, par);
            par[y] = x;
       }

       public  long pow(long a, long b, long MOD) {
            if (b == 0) {
                return 1;
            }
            if (b == 1) {
                return a;
            }
            long val = pow(a, b / 2, MOD);
            if (b % 2 == 0) {
                return val * val % MOD;
            } else {
                return val * (val * a % MOD) % MOD;

            }

        }

        public void minPrimeFactor(int n,int[] s)
        {
            boolean prime[] = new boolean[n+1];
            Arrays.fill(prime, true);
            s[1]=1;
            s[2]=2;
            for(int i=4;i<=n;i+=2)
            {
                prime[i]=false;
                s[i]=2;
            }

            for(int i=3;i<=n;i+=2)
            {
                if(prime[i])
                {
                    s[i]=i;
                    for(int j=2*i;j<=n;j+=i)
                    {
                        prime[j]=false;
                        s[j]=i;
                    }
                }
            }

        }

        public void findAllPrime(int n,ArrayList<Node> al,int s[])
        {
            int curr = s[n];
            int cnt = 1;
            while(n>1)
            {
                n/=s[n];
                if(curr==s[n])
                {
                    cnt++;
                    continue;

                }
                Node n1 = new Node(curr,cnt);
                al.add(n1);

                curr=s[n];
                cnt=1;
            }
        }

        public long findAns(ArrayList<Node> al)
        {
            long sum=1;
            for(int i=0;i<al.size();i++)
            {
                Node n = al.get(i);
                int l=n.i;
                if(l==1)
                    return 1;
                int p = n.p;
                sum*=(long)((Math.pow(l, p+1)-1)/(l-1));

            }

            return sum;
        }

        public int binarySearch(int n,int k)
        {
            int left=1;
            int right=100000000+5;
            int ans=0;
            while(left<=right)
            {
                int mid = (left+right)/2;
                if(n/mid>=k)
                {
                    left = mid+1;
                    ans=mid;
                }
                else
                {
                    right=mid-1;
                }
            }

            return ans;
        }
        public boolean checkPallindrom(String s)
        {
            char ch[] = s.toCharArray();

            for(int i=0;i<s.length()/2;i++)
            {
                if(ch[i]!=ch[s.length()-1-i])
                    return false;
            }
            return true;
        }

        public void dfs_util(ArrayList<Integer>[] al,boolean vis[],int x,int cnt[],int sts[],int fts[])
        {
               vis[x] = true;
                sts[cnt[0]]=x+1;
                boolean flag = false;
                for(int i=0;i<al[x].size();i++)
                {
                    if(!vis[al[x].get(i)])
                    {   flag =true;
                        cnt[0]++;
                        dfs_util(al, vis, al[x].get(i),cnt,sts,fts);
                    }

                }

            cnt[0]++;
            fts[cnt[0]]=x+1;
            return;
        }

        public void dfs(ArrayList[] al,int sts[],int fts[])
        {
            int count[]=new int[1];
            count[0]=0;
           boolean vis[] = new boolean[al.length];
           for(int i=0;i<al.length;i++)
           {
                if(!vis[i])
                {
                    count[0]++;
                    dfs_util(al,vis,i,count,sts,fts);
                }
           }
        }

        private void solve(InputReader inp, PrintWriter out1) {

            int n = inp.nextInt();

            long ans=0;

            for(int i=2;i<=n/2;i++) //starting point
            {
               for(int j=2;i*j<=n;j++)
               {
                   ans+=(long)j*4;
               }
            }
            out1.println(ans);

    }

}

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}
class ele{
    long value;
    long i;
    boolean flag;
    public ele(long value,long i)
    {
        this.value = value;
        this.i=i;
        this.flag = false;
    }
}


import java.util.*;

import java.io.*;

public class Main{

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();

          }

    static class Solver {

        class Node implements Comparable<Node>{
            int i;
            int p;

            Node(int i,int p)
            {
                this.i=i;
                this.p=p;

            }

           public int compareTo(Node n)
            {
                return Integer.compare(this.p, n.p);
            }
        }

        public boolean done(int[] sp,int[] par)
        {
            int root;

            root=findSet(sp[0],par);

           for(int i=1;i<sp.length;i++)
           {
                if(root!=findSet(sp[i], par))
                    return false;
           }
           return true;
        }
       public int findSet(int i,int[] par)
       {
           int x =i;
            boolean flag =false;
            while(par[i]>=0)
            {
                flag = true;
                i=par[i];
            }
            if(flag)
                par[x]=i;
            return i;
       }

       public void unionSet(int i,int j,int[] par)
       {
            int x = findSet(i, par);
            int y = findSet(j, par);
            par[y] = x;
       }

       public  long pow(long a, long b, long MOD) {
            if (b == 0) {
                return 1;
            }
            if (b == 1) {
                return a;
            }
            long val = pow(a, b / 2, MOD);
            if (b % 2 == 0) {
                return val * val % MOD;
            } else {
                return val * (val * a % MOD) % MOD;

            }

        }

        public void minPrimeFactor(int n,int[] s)
        {
            boolean prime[] = new boolean[n+1];
            Arrays.fill(prime, true);
            s[1]=1;
            s[2]=2;
            for(int i=4;i<=n;i+=2)
            {
                prime[i]=false;
                s[i]=2;
            }

            for(int i=3;i<=n;i+=2)
            {
                if(prime[i])
                {
                    s[i]=i;
                    for(int j=2*i;j<=n;j+=i)
                    {
                        prime[j]=false;
                        s[j]=i;
                    }
                }
            }

        }

        public void findAllPrime(int n,ArrayList<Node> al,int s[])
        {
            int curr = s[n];
            int cnt = 1;
            while(n>1)
            {
                n/=s[n];
                if(curr==s[n])
                {
                    cnt++;
                    continue;

                }
                Node n1 = new Node(curr,cnt);
                al.add(n1);

                curr=s[n];
                cnt=1;
            }
        }

        public long findAns(ArrayList<Node> al)
        {
            long sum=1;
            for(int i=0;i<al.size();i++)
            {
                Node n = al.get(i);
                int l=n.i;
                if(l==1)
                    return 1;
                int p = n.p;
                sum*=(long)((Math.pow(l, p+1)-1)/(l-1));

            }

            return sum;
        }

        public int binarySearch(int n,int k)
        {
            int left=1;
            int right=100000000+5;
            int ans=0;
            while(left<=right)
            {
                int mid = (left+right)/2;
                if(n/mid>=k)
                {
                    left = mid+1;
                    ans=mid;
                }
                else
                {
                    right=mid-1;
                }
            }

            return ans;
        }
        public boolean checkPallindrom(String s)
        {
            char ch[] = s.toCharArray();

            for(int i=0;i<s.length()/2;i++)
            {
                if(ch[i]!=ch[s.length()-1-i])
                    return false;
            }
            return true;
        }

        public void dfs_util(ArrayList<Integer>[] al,boolean vis[],int x,int cnt[],int sts[],int fts[])
        {
               vis[x] = true;
                sts[cnt[0]]=x+1;
                boolean flag = false;
                for(int i=0;i<al[x].size();i++)
                {
                    if(!vis[al[x].get(i)])
                    {   flag =true;
                        cnt[0]++;
                        dfs_util(al, vis, al[x].get(i),cnt,sts,fts);
                    }

                }

            cnt[0]++;
            fts[cnt[0]]=x+1;
            return;
        }

        public void dfs(ArrayList[] al,int sts[],int fts[])
        {
            int count[]=new int[1];
            count[0]=0;
           boolean vis[] = new boolean[al.length];
           for(int i=0;i<al.length;i++)
           {
                if(!vis[i])
                {
                    count[0]++;
                    dfs_util(al,vis,i,count,sts,fts);
                }
           }
        }

        private void solve(InputReader inp, PrintWriter out1) {

            int n = inp.nextInt();

            int ans=0;

            for(int i=2;i<=n/2;i++) //starting point
            {
               for(int j=2;i*j<=n;j++)
               {
                   ans+=j*4;
               }
            }
            out1.println(ans);

    }

}

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}
class ele{
    long value;
    long i;
    boolean flag;
    public ele(long value,long i)
    {
        this.value = value;
        this.i=i;
        this.flag = false;
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class A implements Runnable {

    public void run() {
        long startTime = System.nanoTime();

        int n = nextInt();
        long res = 0;
        for (int x = 2; 2 * x <= n; x++) {
            int k = (n / x) - 1;
            res += k * x;
        }
        println(4 * res);

        if (fileIOMode) {
            System.out.println((System.nanoTime() - startTime) / 1e9);
        }
        out.close();
    }

    private long get(long x, int pow, int m) {
        if (pow == 0) {
            return 1;
        }
        if ((pow & 1) == 0) {
            return get(x * x % m, pow >> 1, m);
        } else {
            return x * get(x, pow - 1, m) % m;
        }
    }

    //-----------------------------------------------------------------------------------

    private static boolean fileIOMode;
    private static BufferedReader in;
    private static PrintWriter out;
    private static StringTokenizer tokenizer;

    public static void main(String[] args) throws Exception {
        fileIOMode = args.length > 0 && args[0].equals("!");
        if (fileIOMode) {
            in = new BufferedReader(new FileReader("a.in"));
            out = new PrintWriter("a.out");
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        tokenizer = new StringTokenizer("");

        new Thread(new A()).start();
    }

    private static String nextLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    private static String nextToken() {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    private static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    private static long nextLong() {
        return Long.parseLong(nextToken());
    }

    private static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    private static BigInteger nextBigInteger() {
        return new BigInteger(nextToken());
    }

    private static void print(Object o) {
        if (fileIOMode) {
            System.out.print(o);
        }
        out.print(o);
    }

    private static void println(Object o) {
        if (fileIOMode) {
            System.out.println(o);
        }
        out.println(o);
    }

    private static void printf(String s, Object... o) {
        if (fileIOMode) {
            System.out.printf(s, o);
        }
        out.printf(s, o);
    }
}


import java.io.*;
import java.util.StringTokenizer;

public class BB {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        long ans = 0;
        for (int i = 2; i < n; i++) {
            int tmp = n / i;
            tmp = (tmp - 1);
            if (tmp <= 0) continue;
            ans += 2l * (tmp) * i;
        }
        out.println(ans * 2l);
        out.flush();
        out.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

}


import java.io.*;
import java.util.StringTokenizer;

public class BB {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 2; i < n; i++) {
            int tmp = n / i;
            tmp = (tmp - 1);
            if (tmp <= 0) continue;
            ans += (tmp) * i*2;
        }
        out.println(ans*2);
        out.flush();
        out.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class FunWithIntegers {

    int[] parent;

    void solve() {
        int n = in.nextInt();

        parent = new int[n + 1];
        Arrays.fill(parent, -1);

        for (int i = 2; i <= n; i++) {
            for (int j = i + i; j <= n; j += i) {
                union(i, j);
            }
        }

        int[] sz = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            int j = find(i);
            sz[j]++;
        }
        int[][] comp = new int[n + 1][];
        for (int i = 2; i <= n; i++) {
            comp[i] = new int[sz[i]];
        }
        for (int i = 2; i <= n; i++) {
            int j = find(i);
            comp[j][--sz[j]] = i;
        }

        long ans = 0;
        for (int i = 2; i <= n; i++) {
            long tot = 0;
            for (int x : comp[i]) {
                for (int y = x + x; y <= n; y += x) tot += y / x;
            }
            ans = Math.max(ans, tot);
        }
        out.println(ans * 4);
    }

    int find(int i) {
        if (parent[i] < 0) return i;
        return parent[i] = find(parent[i]);
    }

    void union(int i, int j) {
        int u = find(i), v = find(j);
        if (u == v) return;
        if (parent[u] > parent[v]) {
            int tmp = u; u = v; v = tmp;
        }
        parent[u] += parent[v];
        parent[v] = u;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new FunWithIntegers().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class FunWithIntegers {

    int nc;
    int[] parent;

    void solve() {
        int n = in.nextInt();

        nc = n - 1;
        parent = new int[n + 1];
        Arrays.fill(parent, -1);

        for (int i = 2; i <= n; i++) {
            for (int j = i + i; j <= n; j += i) {
                union(i, j);
            }
        }

        int[] sz = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            int j = find(i);
            sz[j]++;
        }
        int[][] comp = new int[n + 1][];
        for (int i = 2; i <= n; i++) {
            comp[i] = new int[sz[i]];
        }
        for (int i = 2; i <= n; i++) {
            int j = find(i);
            comp[j][--sz[j]] = i;
        }

        int ans = 0;
        for (int i = 2; i <= n; i++) {
            int tot = 0;
            for (int x : comp[i]) {
                for (int y = x + x; y <= n; y += x) tot += y / x;
            }
            ans = Math.max(ans, tot);
        }
        out.println(ans * 4);
    }

    int find(int i) {
        if (parent[i] < 0) return i;
        return parent[i] = find(parent[i]);
    }

    void union(int i, int j) {
        int u = find(i), v = find(j);
        if (u == v) return;
        if (parent[u] > parent[v]) {
            int tmp = u; u = v; v = tmp;
        }
        parent[u] += parent[v];
        parent[v] = u;
        nc--;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new FunWithIntegers().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


						                                import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.util.TreeSet;

				public class Solution1 implements Runnable
				{
				    static final long MOD = 1000000007;
				    static class InputReader
				    {
				        private InputStream stream;
				        private byte[] buf = new byte[1024];
				        private int curChar;
				        private int numChars;
				        private SpaceCharFilter filter;
				        private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

				        public InputReader(InputStream stream)
				        {
				            this.stream = stream;
				        }

				        public int read()
				        {
				            if (numChars==-1)
				                throw new InputMismatchException();

				            if (curChar >= numChars)
				            {
				                curChar = 0;
				                try
				                {
				                    numChars = stream.read(buf);
				                }
				                catch (IOException e)
				                {
				                    throw new InputMismatchException();
				                }

				                if(numChars <= 0)
				                    return -1;
				            }
				            return buf[curChar++];
				        }

				        public String nextLine()
				        {
				            String str = "";
				            try
				            {
				                str = br.readLine();
				            }
				            catch (IOException e)
				            {
				                e.printStackTrace();
				            }
				            return str;
				        }
				        public int nextInt()
				        {
				            int c = read();

				            while(isSpaceChar(c))
				                c = read();

				            int sgn = 1;

				            if (c == '-')
				            {
				                sgn = -1;
				                c = read();
				            }

				            int res = 0;
				            do
				            {
				                if(c<'0'||c>'9')
				                    throw new InputMismatchException();
				                res *= 10;
				                res += c - '0';
				                c = read();
				            }
				            while (!isSpaceChar(c));

				            return res * sgn;
				        }

				        public long nextLong()
				        {
				            int c = read();
				            while (isSpaceChar(c))
				                c = read();
				            int sgn = 1;
				            if (c == '-')
				            {
				                sgn = -1;
				                c = read();
				            }
				            long res = 0;

				            do
				            {
				                if (c < '0' || c > '9')
				                    throw new InputMismatchException();
				                res *= 10;
				                res += c - '0';
				                c = read();
				            }
				            while (!isSpaceChar(c));
				                return res * sgn;
				        }

				        public double nextDouble()
				        {
				            int c = read();
				            while (isSpaceChar(c))
				                c = read();
				            int sgn = 1;
				            if (c == '-')
				            {
				                sgn = -1;
				                c = read();
				            }
				            double res = 0;
				            while (!isSpaceChar(c) && c != '.')
				            {
				                if (c == 'e' || c == 'E')
				                    return res * Math.pow(10, nextInt());
				                if (c < '0' || c > '9')
				                    throw new InputMismatchException();
				                res *= 10;
				                res += c - '0';
				                c = read();
				            }
				            if (c == '.')
				            {
				                c = read();
				                double m = 1;
				                while (!isSpaceChar(c))
				                {
				                    if (c == 'e' || c == 'E')
				                        return res * Math.pow(10, nextInt());
				                    if (c < '0' || c > '9')
				                        throw new InputMismatchException();
				                    m /= 10;
				                    res += (c - '0') * m;
				                    c = read();
				                }
				            }
				            return res * sgn;
				        }

				        public String readString()
				        {
				            int c = read();
				            while (isSpaceChar(c))
				                c = read();
				            StringBuilder res = new StringBuilder();
				            do
				            {
				                res.appendCodePoint(c);
				                c = read();
				            }
				            while (!isSpaceChar(c));

				            return res.toString();
				        }

				        public boolean isSpaceChar(int c)
				        {
				            if (filter != null)
				                return filter.isSpaceChar(c);
				            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
				        }

				        public String next()
				        {
				            return readString();
				        }

				        public interface SpaceCharFilter
				        {
				            public boolean isSpaceChar(int ch);
				        }
				    }

				    public static void main(String args[]) throws Exception
				    {
				        new Thread(null, new Solution1(),"Solution",1<<26).start();
				    }
				    static long gcd(long a, long b)
				    {
				      if (b == 0)
				        return a;
				      return gcd(b, a % b);
				    }
				    static long lcm(long a,long b) {
				    	return (a*b)/gcd(a,b);
				    }
				    ArrayList<Integer> adj[];
				    public void run()
				    {
				    	InputReader sc = new InputReader(System.in);
						PrintWriter w = new PrintWriter(System.out);
						int n = sc.nextInt();
						long ans = 0;
						for(int i= 2;i <= n;i++) {
							long temp = n/i;
							long temp1 = (temp * (temp + 1)/2 - 1) * 4;
							ans += temp1;
						}
						w.println(ans);
						w.close();
				    }
				    long[] fact = new long[100005];
				    long nCr(int n,int r){
				    	long tmp1 = (fact[r] * fact[n-r]) % MOD;
				    	tmp1 = power(tmp1,MOD-2,MOD);
				    	long tmp2 = (fact[n] * tmp1) % MOD;
				    	return tmp2;
	 			    }
				    static long power(long a,long b,long mod) {
						long ans = 1;
						a = a % mod;
						while(b != 0) {
							if(b % 2 == 1) {
								ans = (ans * a) % mod;
							}
							a = (a * a) % mod;
							b = b/2;
						}
						return ans;
					}
				   void pre() {
					   fact[0] = 1;
					   for(int i = 1;i < 100005;i++) {
						   fact[i] = (fact[i-1] * i) % MOD;
					   }
				   }
				    class Pair implements Comparable<Pair>{
				        int a;
				        int b;
				        Pair(int a,int b){
				            this.b = b;
				            this.a = a;

				        }
				        public boolean equals(Object o) {
				            Pair p = (Pair)o;
				            return this.a == p.a && this.b == this.b;
				        }
				        public int hashCode(){
				            return Long.hashCode(a)*27 + Long.hashCode(b)*31;
				        }
				        public int compareTo(Pair p) {
				            return Long.compare(this.a,p.a);
				        }
				    }

				}


// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

// Please name your class Main
public class Main {

	static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    static int read() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    static String readString() throws IOException {
        in.nextToken();
        return in.sval;
	}

	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//InputReader in = new InputReader(System.in);

		int T=1;
		for(int t=0;t<T;t++){

			int n=in.nextInt();

			Solution sol=new Solution();
			sol.solution(n);
		}

	}

}

class Solution{
	//constant variable
	final int MAX=Integer.MAX_VALUE;
	final int MIN=Integer.MIN_VALUE;
	//Set<Integer>adjecent[];
	//////////////////////////////

	public void solution(int n){

		//
		if(n<4){
			msg("0");
			return;
		}
		long res=0;

		for(int i=2;i<=n;i++){
			long start=2;
			long end=n/i;
			//msg(i+"  "+start+"  "+end);
			if(end<start)break;
			long len=end-start+1;
			long sum=(start+end)*len/2;
			res+=sum*4;
		}
		msg(res+"");
	}

	public long C(long fact[],int i,int j){ // C(20,3)=20!/(17!*3!)
		//return fact[i].divide(fact[i-j].multiply(fact[j]));
		long mod=998244353;
		long a=fact[i];
		long b=((fact[i-j]%mod)*(fact[j]%mod))%mod;
		BigInteger B= BigInteger.valueOf(b);
		long binverse=B.modInverse(BigInteger.valueOf(mod)).longValue();
		return ((a)*(binverse%mod))%mod;
	}

	//map operation
	public void put(Map<Integer,Integer>map,int i){
		if(!map.containsKey(i))map.put(i,0);
		map.put(i,map.get(i)+1);
	}

	public void delete(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	/*public void tarjan(int p,int r){
		if(cut)return;
		List<Integer>childs=adjecent[r];
		dis[r]=low[r]=time;
		time++;

		//core for tarjan
		int son=0;
		for(int c:childs){
			if(ban==c||c==p)continue;
			if(dis[c]==-1){
				son++;
				tarjan(r,c);
				low[r]=Math.min(low[r],low[c]);
				if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
					cut=true;
					return;
				}
			}else{
				if(c!=p){
					low[r]=Math.min(low[r],dis[c]);
				}
			}
		}

	}*/

	//helper function I would use
	public void remove(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	public void ascii(String s){
		for(char c:s.toCharArray()){
			System.out.print((c-'a')+" ");
		}
		msg("");
	}

	public int flip(int i){
		if(i==0)return 1;
		else return 0;
	}

	public boolean[] primes(int n){
		boolean A[]=new boolean[n+1];
		for(int i=2;i<=n;i++){
			if(A[i]==false){
				for(int j=i+i;j<=n;j+=i){
					A[j]=true;
				}
			}
		}
		return A;
	}

	public void msg(String s){
		System.out.println(s);
	}

	public void msg1(String s){
		System.out.print(s);
	}

	public int[] kmpPre(String p){
		int pre[]=new int[p.length()];
		int l=0,r=1;
		while(r<p.length()){
			if(p.charAt(l)==p.charAt(r)){
				pre[r]=l+1;
				l++;r++;
			}else{
				if(l==0)r++;
				else l=pre[l-1];
			}
		}
		return pre;
	}

	public boolean isP(String s){
		int l=0,r=s.length()-1;
		while(l<r){
			if(s.charAt(l)!=s.charAt(r))return false;
			l++;r--;
		}
		return true;
	}

	public int find(int nums[],int x){//union find => find method
		if(nums[x]==x)return x;
		int root=find(nums,nums[x]);
		nums[x]=root;
		return root;
	}

	public boolean check(int grid[][],int r,int c){
		if(r<0||c<0||r>=grid.length||c>=grid[0].length)return false;
		return true;
	}

	public int get(int A[],int i){
		if(i<0||i>=A.length)return 0;
		return A[i];
	}
	public int[] copy1(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public int[] copy2(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public void print1(int A[]){
		for(long i:A)System.out.print(i+" ");
		System.out.println();
	}
	public void print2(int A[][]){
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				System.out.print(A[i][j]+" ");
			}System.out.println();
		}
	}

	public int min(int a,int b){
		return Math.min(a,b);
	}

	public int[][] matrixdp(int[][] grid) {
        if(grid.length==0)return new int[][]{};
        int res[][]=new int[grid.length][grid[0].length];
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[0].length;j++){
                res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
            }
        }
        return res;
    }

    public int get(int grid[][],int i,int j){
        if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
        return grid[i][j];
    }

	public int[] suffixArray(String s){
		int n=s.length();
		Suffix A[]=new Suffix[n];

		for(int i=0;i<n;i++){
			A[i]=new Suffix(i,s.charAt(i)-'a',0);
		}

		for(int i=0;i<n;i++){
			if(i==n-1){
				A[i].next=-1;
			}else{
				A[i].next=A[i+1].rank;
			}
		}
		Arrays.sort(A);

		for(int len=4;len<A.length*2;len<<=1){
			int in[]=new int[A.length];
			int rank=0;
			int pre=A[0].rank;
			A[0].rank=rank;
			in[A[0].index]=0;
			for(int i=1;i<A.length;i++){//rank for the first two letter
				if(A[i].rank==pre&&A[i].next==A[i-1].next){
					pre=A[i].rank;
					A[i].rank=rank;
				}else{
					pre=A[i].rank;
					A[i].rank=++rank;
				}
				in[A[i].index]=i;
			}

			for(int i=0;i<A.length;i++){
				int next=A[i].index+len/2;
				if(next>=A.length){
					A[i].next=-1;
				}else{
					A[i].next=A[in[next]].rank;
				}
			}

			Arrays.sort(A);
		}

		int su[]=new int[A.length];
		for(int i=0;i<su.length;i++){
			su[i]=A[i].index;
		}
		return su;
	}

}

//suffix array Struct
class Suffix implements Comparable<Suffix>{
	int index;
	int rank;
	int next;
	public Suffix(int i,int rank,int next){
		this.index=i;
		this.rank=rank;
		this.next=next;
	}

	@Override
	public int compareTo(Suffix other) {
		if(this.rank==other.rank){
			return this.next-other.next;
		}
		return this.rank-other.rank;
	}

	public String toString(){
		return this.index+"   "+this.rank+"   "+this.next+"  ";
	}
}

class Wrapper implements Comparable<Wrapper>{
	int spf;int cnt;
	public Wrapper(int spf,int cnt){
		this.spf=spf;
		this.cnt=cnt;
	}

	@Override
	public int compareTo(Wrapper other) {
		return this.spf-other.spf;
	}
}

    class Node{//what the range would be for that particular node
		boolean state=false;
        int l=0,r=0;
		int ll=0,rr=0;
        public Node(boolean state){
            this.state=state;
        }
    }

	class Seg1{
			int A[];
			public Seg1(int A[]){
				this.A=A;
			}

			public void update(int left,int right,int val,int s,int e,int id){
				if(left<0||right<0||left>right)return;
				if(left==s&&right==e){

					A[id]+=val;
					return;
				}
				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(left>=mid+1){
					update(left,right,val,mid+1,e,id*2+2);
				}else if(right<=mid){
					update(left,right,val,s,mid,id*2+1);
				}else{
					update(left,mid,val,s,mid,id*2+1);
					update(mid+1,right,val,mid+1,e,id*2+2);
				}
			}

			public int query(int i,int add,int s,int e,int id){

				if(s==e&&i==s){
					return A[id]+add;
				}

				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(i>=mid+1){
					return query(i,A[id]+add,mid+1,e,id*2+2);
				}else{
					return query(i,A[id]+add,s,mid,id*2+1);
				}
			}
	}