#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 100000000
bitset<MAX> c(1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  c[1] = 0;
  int ct = 2;
  while (ct < MAX) {
    primes.push_back(ct);
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

int main() {
  int t,n;
  string a = "Ashishgup";
  string f = "FastestFinger";

  sieve(primes);

  cin >> t;

  while (t>0) {
    --t;
    cin >> n;
    // cout << t << " " << n << " " << endl << " == ";

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      cout << f << endl;
      continue;
    }

    // n == 2, sub 1, A wins
    // n is odd, divide by n, A wins
    if (n==2 || n % 2 == 1) {
      cout << a << endl;
      continue;
    }
    // gotta factorize

    vi factors;
    int num2 = 0;
    int numOdd = 0;

    while (n >= 2 && n % 2 == 0) {
      n /= 2;
      num2++;
      // cout << "/2 =" << n << endl;
    }

    auto p = primes.begin();
    ++p; // skip 2

    while (p!=primes.end() && *p <= n) {
      while (n >= *p && n % *p == 0) {
        numOdd ++;
        n /= *p;
        // cout << "/" << *p << " = " << n << endl;
      }
    }

    // 2 * prime, either subtract 1 or divide, lose
    if (num2 == 1 && numOdd == 1) {
      cout << f << "\n";
      continue;
    }

    // 2 * prime * odd, divide odd, win
    if (num2 == 1 && numOdd > 1) {
      cout << a << "\n";
      continue;
    }

    // power of two, must subtract and lose.
    if (num2 > 1 && numOdd == 0) {
      cout << f << "\n";
      continue;
    }

    // last case, 2 * 2^n * odd,  divide odd, win
    if (num2 > 1 && numOdd > 0) {
      cout << a << "\n";
      continue;
    }

  }

}


#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 10000000
vi c(MAX+1,1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  int ct = 2;
  c[1] = 0;
  c[2] = 0;
  while (ct < MAX) {
    primes.push_back(ct);
    if (ct * ct > MAX) break;
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

void a_wins() {
   cout << "Ashishgup\n";
}

void f_wins() {
   cout << "FastestFinger\n";
}

void debug(int i) {
#ifdef DEBUG
   cout << i << " ";
#endif
}

#define DEBUG

int main() {
  int t,n;

  sieve(primes);

  cin >> t;

  while (t--) {
    cin >> n;

    int win = 0;

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      win = 1;
    }

    int log2 = 0;

    while (n>1 && n % 2 == 0) {
       n/=2;
       ++log2;
    }

    // n == 2^x, F wins

    if (n==1 && log2>1) {
      win = 1;
    }

    int isPrime = (n>1);

    auto p = primes.begin();
    ++p; // skip 2

    while (p != primes.end() && *p < n) {
        if (n % *p == 0) {
            isPrime = 0;
            break;
        }
        ++p;
    }

    if (log2 == 1 && isPrime)
      win = 1;

    if (win)
       f_wins();
    else
       a_wins();
  }

}


#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 1000000
vi c(MAX+1,1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  int ct = 2;
  c[1] = 0;
  c[2] = 0;
  while (ct < MAX) {
    primes.push_back(ct);
    if (ct * ct > MAX) break;
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

void a_wins() {
   cout << "Ashishgup\n";
}

void f_wins() {
   cout << "FastestFinger\n";
}

void debug(int i) {
#ifdef DEBUG
   cout << i << " ";
#endif
}

#define DEBUG

int main() {
  int t,n;

  sieve(primes);

  cin >> t;

  while (t>0) {
    --t;
    cin >> n;
    // cout << t << " " << n << " " << "\n" << " == ";

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      debug(1);
      f_wins();
      continue;
    }

    // n == 2, sub 1, A wins
    // n is odd, divide by n, A wins
    if (n % 2 == 1) {
      debug(2);
      a_wins();
      continue;
    }
    // gotta factorize

    vi factors;
    int num2 = 0;
    int numOdd = 0;

    while (n >= 2 && n % 2 == 0) {
      n /= 2;
      num2++;
    }

    if (n==1 && num2>1) { // was power of 2 >= 4
      debug(3);
      f_wins();
      continue;
    }

    auto p = primes.begin();
    ++p; // skip 2

    bool isPrime = (n>1);

    while (p!=primes.end() && *p < n) {
      if (n % *p == 0) {
         isPrime = false;
         break;
      }
      ++p;
    }

    if (num2 == 1 && isPrime) {
       debug(4);
       f_wins();
    } else {
       debug(5);
       a_wins();
    }

  }

}


#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 10000000
vi c(MAX+1,1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  int ct = 2;
  c[1] = 0;
  c[2] = 0;
  while (ct < MAX) {
    primes.push_back(ct);
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

void a_wins() {
   cout << "Ashishgup\n";
}

void f_wins() {
   cout << "FastestFinger\n";
}

void debug(int i) {
#ifdef DEBUG
   cout << i << " ";
#endif
}

#define DEBUG

int isPrime(int n) {
   if (n==1) return 0;

   for(int i=2; i<min(n,50000); ++i)
      if (n % i == 0) return 0;

   return 1;
}

int isPrime2(int n) {

  if (n==1) return 0;

  auto p = primes.begin();

  while (p != primes.end() && *p < n) {
      if (n % *p == 0) {
          return 0;
          break;
      }
      ++p;
  }

  return 1;
}

int main() {
  int t,n;

  sieve(primes);

  cin >> t;

  while (t--) {
    cin >> n;

    int win = 0;

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      win = 1;
    }

    int log2 = 0;

    while (n>1 && n % 2 == 0) {
       n/=2;
       ++log2;
    }

    // n == 2^x, F wins

    if (n==1 && log2>1) {
      win = 1;
    }

    if (log2 == 1 && isPrime2(n))
      win = 1;

    if (win)
       f_wins();
    else
       a_wins();
  }

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

void sieve(vi &primes) {
  vi c(10e6,1); // candidates
  c[0] = 0;
  c[1] = 0;
  int ct = 2;
  while (ct < 10e5) {
    primes.push_back(ct);
    for(int i=ct*ct; i<10e5 && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

int main() {
  int t,n;
  string a = "Ashishgup";
  string f = "FastestFinger";

  sieve(primes);

  cin >> t;

  while (t>0) {
    --t;
    cin >> n;
    // cout << t << " " << n << " ";

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      cout << f << endl;
      continue;
    }

    // n == 2, sub 1, A wins
    // n is odd, divide by n, A wins
    if (n==2 || n % 2 == 1) {
      cout << a << endl;
      continue;
    }
    // gotta factorize

    vi factors;
    int num2 = 0;
    int numOdd = 0;

    while (n >= 2 && n % 2 == 0) {
      n /= 2;
      num2++;
    }

    auto p = primes.begin();
    ++p; // skip 2

    while (p!=primes.end() && *p <= n) {
      while (n >= *p && n % *p == 0) {
        numOdd ++;
        n /= *p;
      }
    }

    // 2 * prime, either subtract 1 or divide, lose
    if (num2 == 1 && numOdd == 1) {
      cout << f << "\n";
      continue;
    }

    // 2 * prime * odd, divide odd, win
    if (num2 == 1 && numOdd > 1) {
      cout << a << "\n";
      continue;
    }

    // power of two, must subtract and lose.
    if (num2 > 1 && numOdd == 0) {
      cout << f << "\n";
      continue;
    }

    // last case, 2 * 2^n * odd,  divide odd, win
    if (num2 > 1 && numOdd > 0) {
      cout << a << "\n";
      continue;
    }

  }

}


#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 1000000
vi c(MAX+1,1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  int ct = 2;
  c[1] = 0;
  c[2] = 0;
  while (ct < MAX) {
    primes.push_back(ct);
    if (ct * ct > MAX) break;
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

void a_wins() {
   cout << "Ashishgup\n";
}

void f_wins() {
   cout << "FastestFinger\n";
}

void debug(int i) {
#ifdef DEBUG
   cout << i << " ";
#endif
}

#define DEBUG

int main() {
  int t,n;

  sieve(primes);

  cin >> t;

  while (t--) {
    cin >> n;

    int win = 0;

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      win = 1;
    }

    int log2 = 0;

    while (n>2 && n % 2 == 0) {
       n/=2;
       ++log2;
    }

    // n == 2^x, F wins

    if (n==1 && log2>1) {
      win = 1;
    }

    int isPrime = (n>1);

    auto p = primes.begin();
    ++p; // skip 2

    while (*p < n) {
        if (n % *p == 0) {
            isPrime = 0;
            break;
        }
        ++p;
    }

    if (log2 == 1 && isPrime)
      win = 1;

    if (win)
       f_wins();
    else
       a_wins();
  }

}


#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 1000000
vi c(MAX+1,1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  int ct = 2;
  c[1] = 0;
  c[2] = 0;
  while (ct < MAX) {
    primes.push_back(ct);
    if (ct * ct > MAX) break;
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

void a_wins() {
   cout << "Ashishgup\n";
}

void f_wins() {
   cout << "FastestFinger\n";
}

void debug(int i) {
#ifdef DEBUG
   cout << i << " ";
#endif
}

#define DEBUG

int main() {
  int t,n;

  sieve(primes);

  cin >> t;

  while (t--) {
    cin >> n;

    int win = 0;

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      win = 1;
    }

    int log2 = 0;

    while (n>1 && n % 2 == 0) {
       n/=2;
       ++log2;
    }

    // n == 2^x, F wins

    if (n==1 && log2>1) {
      win = 1;
    }

    int isPrime = (n>1);

    auto p = primes.begin();
    ++p; // skip 2

    while (p != primes.end() && *p < n) {
        if (n % *p == 0) {
            isPrime = 0;
            break;
        }
        ++p;
    }

    if (log2 == 1 && isPrime)
      win = 1;

    if (win)
       f_wins();
    else
       a_wins();
  }

}


#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 1000000
vi c(MAX+1,1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  int ct = 2;
  c[1] = 0;
  c[2] = 0;
  while (ct < MAX) {
    primes.push_back(ct);
    if (ct * ct > MAX) break;
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

void a_wins() {
   cout << "Ashishgup\n";
}

void f_wins() {
   cout << "FastestFinger\n";
}

void debug(int i) {
#ifdef DEBUG
   cout << i << " ";
#endif
}

#define DEBUG

int main() {
  int t,n;

  sieve(primes);

  cin >> t;

  while (t--) {
    cin >> n;

    int win = 0;

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      win = 1;
    }

    int log2 = 0;

    while (n>1 && n % 2 == 0) {
       n/=2;
       ++log2;
    }

    // n == 2^x, F wins

    if (n==1 && log2>1) {
      win = 1;
    }

    int isPrime = (n>1);

    auto p = primes.begin();
    ++p; // skip 2

    while (*p < n) {
        if (n % *p == 0) {
            isPrime = 0;
            break;
        }
        ++p;
    }

    if (log2 == 1 && isPrime)
      win = 1;

    if (win)
       f_wins();
    else
       a_wins();
  }

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef set<int> si;

#define MAX 100000000
bitset<MAX> c(1); // candidates

void sieve(vi &primes) {
  c[0] = 0;
  c[1] = 0;
  int ct = 2;
  while (ct < MAX) {
    primes.push_back(ct);
    for(int i=ct*ct; i<MAX && i > 0; i+=ct) {
      c[i] = 0;
    }
    while (c[++ct] == 0);
  }
}

vi primes;

int main() {
  int t,n;
  string a = "Ashishgup";
  string f = "FastestFinger";

  sieve(primes);

  cin >> t;

  while (t>0) {
    --t;
    cin >> n;
    // cout << t << " " << n << " " << "\n" << " == ";

    // Case analysis:
    // n == 1, no move, F wins

    if (n==1) {
      cout << f << "\n";
      continue;
    }

    // n == 2, sub 1, A wins
    // n is odd, divide by n, A wins
    if (n==2 || n % 2 == 1) {
      cout << a << "\n";
      continue;
    }
    // gotta factorize

    vi factors;
    int num2 = 0;
    int numOdd = 0;

    while (n >= 2 && n % 2 == 0) {
      n /= 2;
      num2++;
      // cout << "/2 =" << n << "\n";
    }

    auto p = primes.begin();
    ++p; // skip 2

    while (p!=primes.end() && *p <= n) {
      while (n >= *p && n % *p == 0) {
        numOdd ++;
        n /= *p;
        // cout << "/" << *p << " = " << n << "\n";
      }
    }

    // 2 * prime, either subtract 1 or divide, lose
    if (num2 == 1 && numOdd == 1) {
      cout << f << "\n";
      continue;
    }

    // 2 * prime * odd, divide odd, win
    if (num2 == 1 && numOdd > 1) {
      cout << a << "\n";
      continue;
    }

    // power of two, must subtract and lose.
    if (num2 > 1 && numOdd == 0) {
      cout << f << "\n";
      continue;
    }

    // last case, 2 * 2^n * odd,  divide odd, win
    if (num2 > 1 && numOdd > 0) {
      cout << a << "\n";
      continue;
    }

  }

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            int temp=sqrt(n);
            for(int i=temp;i>=3;i--)
            {
                if(n%i==0&&(n/i)%2+i%2==1)
                {
                    if(i%2==1)
                    n=n/i;
                    else
                    n=i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include<bits/stdc++.h>

using namespace std;
#define s1 "FastestFinger"
#define s2 "Ashishgup"
#define all(c) (c).begin(), (c).end()

typedef long long int ll;

int fun(int n) {
    vector<int> factor;
    int d = 2;
    while (n > 1) {
        while (n % d == 0) {
            factor.push_back(d);
            n /= d;
        }
        d += 1;
        if (d * d > n) {
            if (n > 1) {
                factor.push_back(n);
                break;
            }
        }
    }
    return *max_element(all(factor));
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		if (n == 1)
		{
            cout << s1 << endl;
            continue;
        }

        if (n == 2 or n & 1)
		{
            cout << s2 << endl;
            continue;
        }

        if (!(n & (n - 1)))
		{
            cout << "s1" << endl;
            continue;
        }
        // cout <<" prime[n]: "<< prime[n]<<endl;
        if ((fun(n) * 2) % n == 0)
		{
            cout << "s1" << endl;
        }
		else
		{
            cout << "s2" << endl;
        }
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            if(n%3==0)
            {
                n=n/3;
            }
        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else
        {
            if(n%2==1)
                cout<<s1<<endl;
            else
            {
                int c=0;
                while(n%2!=1)
                {
                    c++;
                    n=n/2;
                }
                if(n==1)
                {
                    c++;
                }
                if(c%2==1)
                {
                    cout<<s2<<endl;
                }
                else
                    cout<<s1<<endl;
            }
        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            int temp=sqrt(n);
            if(temp%2==0)
            temp--;
            for(int i=temp;i>=3;i-=2)
            {
                if(n%i==0&&(n/i)%2==0)
                {
                    n=n/i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            for(int i=sqrt(n)/2*2;i>=3;i-=2)
            {
                if(n%i==0&&(n/i)%2==0)
                {
                    n=n/i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            for(int i=3;i<=sqrt(n);i+=2)
            {
                if(n%i==0&&(n/i)%2==0)
                {
                    n=n/i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            int temp=sqrt(n);
            for(int i=temp;i>=3;i--)
            {
                if(n%i==0&&(n/i)%2+i%2==`1)
                {
                    n=n/i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include<bits/stdc++.h>

using namespace std;
#define s1 "FastestFinger"
#define s2 "Ashishgup"
#define all(c) (c).begin(), (c).end()

typedef long long int ll;

int fun(int n) {
    vector<int> factor;
    int d = 2;
    while (n > 1) {
        while (n % d == 0) {
            factor.push_back(d);
            n /= d;
        }
        d += 1;
        if (d * d > n) {
            if (n > 1) {
                factor.push_back(n);
                break;
            }
        }
    }
    return *max_element(all(factor));
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		if (n == 1)
		{
            cout << s1 << endl;
            continue;
        }

        if (n == 2 or n & 1)
		{
            cout << s2 << endl;
            continue;
        }

        if (!(n & (n - 1)))
		{
            cout << s1 << endl;
            continue;
        }
        // cout <<" prime[n]: "<< prime[n]<<endl;
        if ((fun(n) * 2) % n == 0)
		{
            cout << s1 << endl;
        }
		else
		{
            cout << s2 << endl;
        }
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
                n=n/2;
        if(n%2==1||n==2)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            int temp=sqrt(n);
            for(int i=temp;i>=3;i--)
            {
                if(n%i==0&&(n/i)%2+i==1)
                {
                    n=n/i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            int temp=sqrt(n);
            for(int i=temp;i>=3;i--)
            {
                if(n%i==0&&(n/i)%2+i%2==1)
                {
                    n=n/i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define s1 "Ashishgup"
#define s2 "FastestFinger"
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<s2<<endl;
        }
        else if(n==2)
            cout<<s1<<endl;
            else if(n%2==1)
                cout<<s1<<endl;
        else
        {
            int c=n;
            int temp=sqrt(n);
            for(int i=temp;i>=3;i--)
            {
                if(n%i==0&&(n/i)%2+i==`1)
                {
                    n=n/i;
                    break;
                }
            }

        if(n%2==1||n==2||c==n)
            cout<<s2<<endl;
        else

                    cout<<s1<<endl;

        }

    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
int prime(int n)
{
    int z = sqrt(n);
    for (int i = 2; i <= z; i++)
    {
        if (n % i != 0)
            return 0;
    }
    return 1;
}
signed main()
{
    rootdada;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    //  freopen("error.txt", "w", stderr);
#endif
    test
    {
        int n;
        cin >> n;
        if (n == 1)
            cout << "FastestFinger" << endl;
        else if (n % 2 == 1 || n == 2)
            cout << "Ashishgup" << endl;
        else if ((n & (n - 1)) == 0) //power of 2
            cout << "FastestFinger" << endl;
        else
        {
            int two = n;
            int c = 0;
            while (two % 2 == 0)
            {
                two /= 2;
                c++;
            }

            if (prime(n) && c == 1)
                cout << "FastestFinger" << endl;
            else
                cout << "Ashishgup" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
int two, other;
void primeFactors(int n)
{
    while (n % 2 == 0)
    {
        two++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            other++;
            n = n / i;
        }
    }
    if (n > 2)
        other++;
}
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     //   freopen("output.txt", "w", stdout);
    //     //  freopen("error.txt", "w", stderr);
    // #endif
    test
    {
        int n;
        cin >> n;
        two = 0, other = 0;
        if (n == 1)
            cout << "FastestFinger" << endl;
        else if (n % 2 == 1 || n == 2)
            cout << "Ashishgup" << endl;
        else if ((n & (n - 1)) == 0) //power of 2
            cout << "FastestFinger" << endl;
        else
        {
            primeFactors(n);
            // cout << other << " " << two << endl;
            if (other % 2 == 0)
            {
                if (two == 1)
                    cout << "FastestFinger" << endl;
                else
                {
                    cout << "Ashishgup" << endl;
                }
            }
            else
            {
                if (two != 1)
                    cout << "FastestFinger" << endl;
                else
                {
                    cout << "Ashishgup" << endl;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

signed main()
{
    rootdada;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    //  freopen("error.txt", "w", stderr);
#endif
    test
    {
        int n;
        cin >> n;
        int two = n;
        if (n == 1)
        {
            cout << "FastestFinger" << endl;
            continue;
        }
        if (n % 2 == 1 || n == 2)
        {
            cout << "Ashishgup" << endl;
            continue;
        }
        if (n % 4 == 0 and n != 4)
        {
            cout << "Ashishgup" << endl;
            continue;
        }
        while (two % 2 == 0)
            two /= 2;

        if (two == 1)
        {
            cout << "FastestFinger" << endl;
            continue;
        }

        int c = 0;
        int x = n;
        for (int i = 3; i * i <= x; i++)
        {
            if ((x % i) != 0 || i % 2 == 0)
                continue;
            while (x % i == 0)
            {
                c++;
                x /= i;
            }
        }
        if (x != 2 and x > 1)
            c++;
        c++;
        if (c % 2 == 1)
        {
            cout << "Ashishgup" << endl;
            continue;
        }
        else
        {
            cout << "FastestFinger" << endl;
            continue;
        }
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
int two, other;
void primeFactors(int n)
{
    while (n % 2 == 0)
    {
        two++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            other++;
            n = n / i;
        }
    }
    if (n > 2)
        other++;
}
signed main()
{
    rootdada;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    //  freopen("error.txt", "w", stderr);
#endif
    test
    {
        int n;
        cin >> n;
        two = 0, other = 0;
        if (n == 1)
            cout << "FastestFinger" << endl;
        else if (n % 2 == 1 || n == 2)
            cout << "Ashishgup" << endl;
        else if ((n & (n - 1)) == 0) //power of 2
            cout << "FastestFinger" << endl;
        else
        {
            primeFactors(n);
            // cout << other << " " << two << endl;
            if (other % 2 != 0)
            {
                if (two == 1)
                    cout << "FastestFinger" << endl;
                else
                {
                    cout << "Ashishgup" << endl;
                }
            }
            else
            {
                if (two == 1)
                    cout << "Ashishgup" << endl;
                else
                {
                    cout << "FastestFinger" << endl;
                }
            }
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
int two, other;
void primeFactors(int n)
{
    while (n % 2 == 0)
    {
        two++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            other++;
            n = n / i;
        }
    }
    if (n > 2)
        other++;
}
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     //   freopen("output.txt", "w", stdout);
    //     //  freopen("error.txt", "w", stderr);
    // #endif
    test
    {
        int n;
        cin >> n;
        two = 0, other = 0;
        if (n == 1)
            cout << "FastestFinger" << endl;
        else if (n % 2 == 1 || n == 2)
            cout << "Ashishgup" << endl;
        else if ((n & (n - 1)) == 0) //power of 2
            cout << "FastestFinger" << endl;
        else
        {
            primeFactors(n);
            // cout << other << " " << two << endl;
            if (two == 1 && other == 1)
            {
                cout << "FastestFinger" << endl;
            }
            else
            {
                cout << "Ashishgup" << endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
int two, other;
void primeFactors(int n)
{
    while (n % 2 == 0)
    {
        two++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            other++;
            n = n / i;
        }
    }
    if (n != 1)
        other++;
}
signed main()
{
    rootdada;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    //  freopen("error.txt", "w", stderr);
#endif
    test
    {
        int n;
        cin >> n;
        int two = 0, other = 0;
        if (n == 1)
            cout << "FastestFinger" << endl;
        else if (n % 2 == 1 || n == 2)
            cout << "Ashishgup" << endl;
        // else if ((n & (n - 1)) == 0) //power of 2
        //     cout << "FastestFinger" << endl;
        else
        {
            int x = n;
            while (n % 2 == 0)
                n /= 2;
            if (n == 1 || x / n == 2)
                cout << "FastestFinger" << endl;
            else
                cout << "Ashishgup" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;
ll n,m,ans=0;
int cat[228228]={0};
std::vector<int> v[228228];

void dfs(ll node,ll cas,ll parent){

  ll flag = 1;

  if(cas>m)
    return;

  for(ll i=0;i<v[node].size();i++){
      if(v[node][i]!=parent){
            flag=0;
            dfs(v[node][i],cas*cat[v[node][i]]+cat[v[node][i]],node);}
  }
  ans+=flag;
}

int main()
{

  cin>>n>>m;

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

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

    int x,y;
    scanf("%d%d",&x,&y);
    v[x].push_back(y);
    v[y].push_back(x);

  }
  dfs(1,cat[1],0);

  cout<<ans<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;
int n,m,ans=0;
std::vector<int> cat(100000);
std::vector<int> v[1000];
int bis[200000]={0};

void dfs(int node,int m,int cas,int cont){

  bis[node]=1;
  if(cat[node]==1 && cont==1){
    cont=1;
    cas++;}
  else if(cat[node]==1 && cont ==0){
    cas=1;
    cont =1;
  }
  else {
    cont=0;
    cas=0;}

  if(cas>m)
    return;
  if(cas<=m && v[node].size()==0){
    ans++;
  //cout<<ans<<"\n";
}

//  if(cont==1 && cat[node]==1)

  for(int i=0;i<v[node].size();i++){
      if(bis[v[node][i]]==0)
            dfs(v[node][i],m,cas,cont);
  }

}

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

  for(int i=1;i<=n;i++){
    int x;
    cin>>x;

    cat[i]=x;
  }

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

    int x,y;
    cin>>x>>y;
    int j=min(x,y);
    int k=max(x,y);
    v[j].push_back(k);
   //v[y].push_back(x);

  }
  //cout<<v[2].size()<<"\n";
  dfs(1,m,0,0);

  cout<<ans<<"\n";
//
// for(int i=0;i<5;i++)
//   cout<<bis[i]<<" ";

}


#include <bits/stdc++.h>
#define ll long long
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;
int n,m,ans=0;
std::vector<int> cat(100000);
std::vector<int> v[1000];
int bis[200000]={0};

void dfs(int node,int m,int cas,int cont){

  bis[node]=1;
  if(cat[node]==1 && cont==1){
    cont=1;
    cas++;}
  else if(cat[node]==1 && cont ==0){
    cas=1;
    cont =1;
  }
  else {
    cont=0;
    cas=0;}

  if(cas>m)
    return;
  if(cas<=m && v[node].size()==1){
    ans++;
  //cout<<ans<<"\n";
}

//  if(cont==1 && cat[node]==1)

  for(int i=0;i<v[node].size();i++){
      if(bis[v[node][i]]==0)
            dfs(v[node][i],m,cas,cont);
  }

}

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

  for(int i=1;i<=n;i++){
    int x;
    cin>>x;

    cat[i]=x;
  }

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

    int x,y;
    cin>>x>>y;
    // int j=min(x,y);
    // int k=max(x,y)
    v[x].push_back(y);
   v[y].push_back(x);

  }
  //cout<<v[2].size()<<"\n";
  dfs(1,m,0,0);

  cout<<ans<<"\n";
//
// for(int i=0;i<5;i++)
//   cout<<bis[i]<<" ";

}


#include <bits/stdc++.h>
#define ll long long
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;
int n,m,ans=0;
std::vector<int> cat(100000);
std::vector<int> v[1000];
//int bis[200000]={0};

void dfs(int node,int m,int cas,int cont,int parent){

  int flag = 1;
  //
  // if(bis[node]==1)
  //   return;

  //bis[node]=1;
  if(cat[node]==1 && cont==1){
    cont=1;
    cas++;}
  else if(cat[node]==1 && cont ==0){
    cas=1;
    cont =1;
  }
  else {
    cont=0;
    cas=0;}

  if(cas>m)
    return;
//   if(cas<=m && v[node].size()==1){
//     ans++;
//   //cout<<ans<<"\n";
// }

//  if(cont==1 && cat[node]==1)

  for(int i=0;i<v[node].size();i++){
      if(v[node][i]!=parent){
            flag=0;
            dfs(v[node][i],m,cas,cont,node);}
  }

  if(flag==1 && cas<=m )
    ans++;

}

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

  for(int i=1;i<=n;i++){
    int x;
    cin>>x;

    cat[i]=x;
  }

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

    int x,y;
    cin>>x>>y;
    // int j=min(x,y);
    // int k=max(x,y)
    v[x].push_back(y);
   v[y].push_back(x);

  }
  //cout<<v[2].size()<<"\n";

  // for(int i=1;i<5;i++){
  //   for(int j=0;j<v[i].size();j++)
  //     cout<<v[i][j]<<" ";
  //     cout<<"\n";
  // }
  dfs(1,m,0,0,0);

  cout<<ans<<"\n";
//
// for(int i=0;i<5;i++)
//   cout<<bis[i]<<" ";

}


#include <bits/stdc++.h>
#define ll long long
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);

using namespace std;
ll n,m,ans=0;
std::vector<ll> cat;
std::vector<ll> v[100000];
//ll bis[200000]={0};
// void go(ll v,ll pr,ll k){
// 	if(k>m)return;
// 	ll ok=1;
// 	for(ll i=0;i<a[v].size();i++){
//       if(a[v][i]!=pr){
//             ok=0;
//             go(a[v][i],v,  k*c[a[v][i]]+c[a[v][i]]);}}
// 	           o+=ok;
// }

void dfs(ll node,ll m,ll cas,ll parent){

  ll flag = 1;

  if(cas>m)
    return;

  for(ll i=0;i<v[node].size();i++){
      if(v[node][i]!=parent){
            flag=0;
            dfs(v[node][i],m,(cas+1)*cat[v[node][i]],node);}
  }
  ans+=flag;
}

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

  cat.push_back(0);
  for(ll i=1;i<=n;i++){
    ll x;
    cin>>x;
    cat.push_back(x);

  }

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

    ll x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);

  }
  dfs(1,m,cat[1],0);

  cout<<ans<<"\n";

}


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

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("hull1.in"));
            out = new PrintWriter(new File("hull1.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }

        tok = new StringTokenizer("");
        new A().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        if (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    static class Pair implements Comparable<Pair> {

        int a;
        int b;

        public Pair( int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {

            if (o.a > a) return -1;
            if (o.a < a) return 1;
            if (o.b < b) return 1;
            if (o.b > b) return -1;
            return 0;
        }
    }

    boolean used[];
    ArrayList<Integer>[] ar;
    int color[];
    boolean cycle = false;
    int m;
    Set<Integer> set = new HashSet<Integer>();
    int cats[];
    boolean[] list;

    void d(int v, int cnt, boolean last) {
        used[v] = true;
        boolean cat = false;
        if (cats[v] == 1 && last == true) {
            cnt++;
            cat = true;
        } else if (cats[v] == 1 && last == false) {
            if (cnt <= m) cnt = 1;
            cat = true;
        } else {
            if (cnt <= m) cnt = 0;
        }
        if (ar[v].size() == 1 && v != 1) {
            if (cnt <= m) {
                set.add(v);
//                System.out.println(v);
            }

        }
        for (int i = 0; i < ar[v].size(); i++) {
            int vv = ar[v].get(i);
            if (!used[vv]) d(vv,cnt,cat);
        }

    }

    void solve() throws IOException {
        int n = nextInt();
        m = nextInt();
        cats = new int[n+1];
        used = new boolean[n+1];
        ar = new ArrayList[n+1];
        list = new boolean[n+1];
        Arrays.fill(list,true);
        for (int i = 0; i < n+1; i++) {
            ar[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= n ; i++) {
            cats[i] = nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            int a = nextInt();
            int b = nextInt();
//            int tmp = a;
            ar[a].add(b);
            ar[b].add(a);
        }

        d(1,0,false);
        out.println(set.size());

    }

}


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

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("hull1.in"));
            out = new PrintWriter(new File("hull1.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }

        tok = new StringTokenizer("");
        new A().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        if (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    static class Pair implements Comparable<Pair> {

        int a;
        int b;

        public Pair( int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {

            if (o.a > a) return -1;
            if (o.a < a) return 1;
            if (o.b < b) return 1;
            if (o.b > b) return -1;
            return 0;
        }
    }

    boolean used[];
    ArrayList<Integer>[] ar;
    int color[];
    boolean cycle = false;
    int m;
    Set<Integer> set = new HashSet<Integer>();
    int cats[];

    void d(int v, int cnt, boolean last) {
        used[v] = true;
        boolean cat = false;
        if (cats[v] == 1 && last == true) {
            cnt++;
            cat = true;
        } else {
            if (cnt <= m) cnt = 0;
        }
        if (ar[v].size() == 0) {
            if (cnt <= m) {
                set.add(v);
//                System.out.println(v);
            }

        }
        for (int i = 0; i < ar[v].size(); i++) {
            int vv = ar[v].get(i);
            if (!used[vv]) d(vv,cnt,cat);
        }

    }

    void solve() throws IOException {
        int n = nextInt();
        m = nextInt();
        cats = new int[n+1];
        used = new boolean[n+1];
        ar = new ArrayList[n+1];
        for (int i = 0; i < n+1; i++) {
            ar[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= n ; i++) {
            cats[i] = nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            int a = nextInt();
            int b = nextInt();
            ar[a].add(b);
        }
        d(1,0,true);
        System.out.println(set.size());

    }

}


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

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("hull1.in"));
            out = new PrintWriter(new File("hull1.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }

        tok = new StringTokenizer("");
        new A().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        if (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    static class Pair implements Comparable<Pair> {

        int a;
        int b;

        public Pair( int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {

            if (o.a > a) return -1;
            if (o.a < a) return 1;
            if (o.b < b) return 1;
            if (o.b > b) return -1;
            return 0;
        }
    }

    boolean used[];
    ArrayList<Integer>[] ar;
    int color[];
    boolean cycle = false;
    int m;
    Set<Integer> set = new HashSet<Integer>();
    int cats[];
    boolean[] list;

    void d(int v, int cnt, boolean last) {
        used[v] = true;
        boolean cat = false;
        if (cats[v] == 1 && last == true) {
            cnt++;
            cat = true;
        } else if (cats[v] == 1 && last == false) {
            if (cnt <= m) cnt = 1;
            cat = true;
        } else {
            if (cnt <= m) cnt = 0;
        }
        if (list[v]) {
            if (cnt <= m) {
                set.add(v);
//                System.out.println(v);
            }

        }
        for (int i = 0; i < ar[v].size(); i++) {
            int vv = ar[v].get(i);
            if (!used[vv]) d(vv,cnt,cat);
        }

    }

    void solve() throws IOException {
        int n = nextInt();
        m = nextInt();
        cats = new int[n+1];
        used = new boolean[n+1];
        ar = new ArrayList[n+1];
        list = new boolean[n+1];
        Arrays.fill(list,true);
        for (int i = 0; i < n+1; i++) {
            ar[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= n ; i++) {
            cats[i] = nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            int a = nextInt();
            int b = nextInt();
//            int tmp = a;
            ar[a].add(b);
            ar[b].add(a);
            list[a] = false;
        }
        d(1,0,false);
        out.println(set.size());

    }

}


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

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("hull1.in"));
            out = new PrintWriter(new File("hull1.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }

        tok = new StringTokenizer("");
        new A().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        if (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    static class Pair implements Comparable<Pair> {

        int a;
        int b;

        public Pair( int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {

            if (o.a > a) return -1;
            if (o.a < a) return 1;
            if (o.b < b) return 1;
            if (o.b > b) return -1;
            return 0;
        }
    }

    boolean used[];
    ArrayList<Integer>[] ar;
    int color[];
    boolean cycle = false;
    int m;
    Set<Integer> set = new HashSet<Integer>();
    int cats[];

    void d(int v, int cnt, boolean last) {
        used[v] = true;
        boolean cat = false;
        if (cats[v] == 1 && last == true) {
            cnt++;
            cat = true;
        } else if (cats[v] == 1 && last == false) {
            if (cnt <= m) cnt = 1;
            cat = true;
        } else {
            if (cnt <= m) cnt = 0;
        }
        if (ar[v].size() == 0) {
            if (cnt <= m) {
                set.add(v);
//                System.out.println(v);
            }

        }
        for (int i = 0; i < ar[v].size(); i++) {
            int vv = ar[v].get(i);
            if (!used[vv]) d(vv,cnt,cat);
        }

    }

    void solve() throws IOException {
        int n = nextInt();
        m = nextInt();
        cats = new int[n+1];
        used = new boolean[n+1];
        ar = new ArrayList[n+1];
        for (int i = 0; i < n+1; i++) {
            ar[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= n ; i++) {
            cats[i] = nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            int a = nextInt();
            int b = nextInt();
            int tmp = a;
            if (a > b) {
                a = b;
                b = tmp;
            }
            ar[a].add(b);
//            ar[b].add(a);
        }
        d(1,0,false);
        out.println(set.size());

    }

}


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

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("hull1.in"));
            out = new PrintWriter(new File("hull1.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }

        tok = new StringTokenizer("");
        new A().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        if (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    static class Pair implements Comparable<Pair> {

        int a;
        int b;

        public Pair( int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {

            if (o.a > a) return -1;
            if (o.a < a) return 1;
            if (o.b < b) return 1;
            if (o.b > b) return -1;
            return 0;
        }
    }

    boolean used[];
    ArrayList<Integer>[] ar;
    int color[];
    boolean cycle = false;
    int m;
    Set<Integer> set = new HashSet<Integer>();
    int cats[];

    void d(int v, int cnt, boolean last) {
        used[v] = true;
        boolean cat = false;
        if (cats[v] == 1 && last == true) {
            cnt++;
            cat = true;
        } else if (cats[v] == 1 && last == false) {
            if (cnt <= m) cnt = 1;
            cat = true;
        } else {
            if (cnt <= m) cnt = 0;
        }
        if (ar[v].size() == 0) {
            if (cnt <= m) {
                set.add(v);
//                System.out.println(v);
            }

        }
        for (int i = 0; i < ar[v].size(); i++) {
            int vv = ar[v].get(i);
            if (!used[vv]) d(vv,cnt,cat);
        }

    }

    void solve() throws IOException {
        int n = nextInt();
        m = nextInt();
        cats = new int[n+1];
        used = new boolean[n+1];
        ar = new ArrayList[n+1];
        for (int i = 0; i < n+1; i++) {
            ar[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= n ; i++) {
            cats[i] = nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            int a = nextInt();
            int b = nextInt();
            ar[a].add(b);
        }
        d(1,0,false);
        out.println(set.size());

    }

}


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

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("hull1.in"));
            out = new PrintWriter(new File("hull1.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }

        tok = new StringTokenizer("");
        new A().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        if (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    static class Pair implements Comparable<Pair> {

        int a;
        int b;

        public Pair( int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {

            if (o.a > a) return -1;
            if (o.a < a) return 1;
            if (o.b < b) return 1;
            if (o.b > b) return -1;
            return 0;
        }
    }

    boolean used[];
    ArrayList<Integer>[] ar;
    int color[];
    boolean cycle = false;
    int m;
    Set<Integer> set = new HashSet<Integer>();
    int cats[];

    void d(int v, int cnt, boolean last) {
        used[v] = true;
        boolean cat = false;
        if ((cats[v] == 1 && last == true) || (cats[v] == 1 && cnt == 0)) {
            cnt++;
            cat = true;
        } else {
            if (cnt <= m) cnt = 0;
        }
        if (ar[v].size() == 0) {
            if (cnt <= m) {
                set.add(v);
//                System.out.println(v);
            }

        }
        for (int i = 0; i < ar[v].size(); i++) {
            int vv = ar[v].get(i);
            if (!used[vv]) d(vv,cnt,cat);
        }

    }

    void solve() throws IOException {
        int n = nextInt();
        m = nextInt();
        cats = new int[n+1];
        used = new boolean[n+1];
        ar = new ArrayList[n+1];
        for (int i = 0; i < n+1; i++) {
            ar[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= n ; i++) {
            cats[i] = nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            int a = nextInt();
            int b = nextInt();
            ar[a].add(b);
        }
        d(1,0,false);
        System.out.println(set.size());

    }

}


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

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        try {
            in = new BufferedReader(new FileReader("hull1.in"));
            out = new PrintWriter(new File("hull1.out"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }

        tok = new StringTokenizer("");
        new A().solve();
        out.flush();
        out.close();
    }

    String nextTok() throws IOException {
        if (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    static class Pair implements Comparable<Pair> {

        int a;
        int b;

        public Pair( int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair o) {

            if (o.a > a) return -1;
            if (o.a < a) return 1;
            if (o.b < b) return 1;
            if (o.b > b) return -1;
            return 0;
        }
    }

    boolean used[];
    ArrayList<Integer>[] ar;
    int color[];
    boolean cycle = false;
    int m;
    Set<Integer> set = new HashSet<Integer>();
    int cats[];
    boolean[] list;

    void d(int v, int cnt, boolean last) {
        used[v] = true;
        boolean cat = false;
        if (cats[v] == 1 && last == true) {
            cnt++;
            cat = true;
        } else if (cats[v] == 1 && last == false) {
            if (cnt <= m) cnt = 1;
            cat = true;
        } else {
            if (cnt <= m) cnt = 0;
        }
        if (list[v]) {
            if (cnt <= m) {
                set.add(v);
//                System.out.println(v);
            }

        }
        for (int i = 0; i < ar[v].size(); i++) {
            int vv = ar[v].get(i);
            if (!used[vv]) d(vv,cnt,cat);
        }

    }

    void solve() throws IOException {
        int n = nextInt();
        m = nextInt();
        cats = new int[n+1];
        used = new boolean[n+1];
        ar = new ArrayList[n+1];
        list = new boolean[n+1];
        Arrays.fill(list,true);
        for (int i = 0; i < n+1; i++) {
            ar[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= n ; i++) {
            cats[i] = nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            int a = nextInt();
            int b = nextInt();
//            int tmp = a;
            ar[a].add(b);
            ar[b].add(a);
            list[a] = false;
        }
        list[1] = false;
        d(1,0,false);
        out.println(set.size());

    }

}


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

public class CF321C{

    static int m;

    CF321C p;
    int ct;
    int in;
    List<CF321C> v = new ArrayList<CF321C>();

    static long r(CF321C s, int mc) {
        int q = mc;

        if (s.ct == 1) {
            q--;
        }

        /*System.out.println(s.in + " " + q);*/

        if (q<0) {
            return 0;
        }

        if (s.ct == 0) {
            q = m;
        }

        if (s.v.size() == 1 && s.in != 1) {
            return 1;
        }

        long rs = 0;
        for (int i=0; i<s.v.size(); i++) {
            if (s.p == null || s.v.get(i).in != s.p.in) {
                s.v.get(i).p = s;
                rs += r(s.v.get(i), q);
            }
        }
        return rs;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = sc.nextInt();
        m = sc.nextInt();

        int c[] = new int[n];

        for (int i=0; i<n; i++) {
            c[i] = sc.nextInt();
        }

        CF321C g[] = new CF321C[n];

        for (int i=0; i<n; i++) {
            g[i] = new CF321C();
            g[i].in = i+1;
            g[i].ct = c[i];
        }

        for (int i=1; i<n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            g[a-1].v.add(g[b-1]);
            g[b-1].v.add(g[a-1]);
        }

        out.println(r(g[0], m));

        out.close();
    }
}


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

public class CF321C{

    static int m;

    CF321C p;
    int ct;
    int in;
    List<CF321C> v = new ArrayList<CF321C>();

    static long r(CF321C s, int mc) {
        int q = mc;

        if (s.ct == 1) {
            q--;
        }

        /*System.out.println(s.in + " " + q);*/

        if (q<0) {
            return 0;
        }

        if (s.ct == 0) {
            q = m;
        }

        if (s.v.size() == 1) {
            return 1;
        }

        long rs = 0;
        for (int i=0; i<s.v.size(); i++) {
            if (s.v.get(i) != s.p) {
                s.v.get(i).p = s;
                rs += r(s.v.get(i), q);
            }
        }
        return rs;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = sc.nextInt();
        m = sc.nextInt();

        int c[] = new int[n];

        for (int i=0; i<n; i++) {
            c[i] = sc.nextInt();
        }

        CF321C g[] = new CF321C[n];

        for (int i=0; i<n; i++) {
            g[i] = new CF321C();
            g[i].in = i+1;
            g[i].ct = c[i];
        }

        for (int i=0; i<n-1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            g[a-1].v.add(g[b-1]);
            g[b-1].v.add(g[a-1]);
        }

        out.println(r(g[0], m));

        out.close();
    }
}


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

public class CF321C{

    static int m;

    CF321C p;
    int ct;
    int in;
    List<CF321C> v = new ArrayList<CF321C>();

    static long r(CF321C s, int mc) {
        int q = mc;

        if (s.ct == 1) {
            q--;
        }

        /*System.out.println(s.in + " " + q);*/

        if (q<0) {
            return 0;
        }

        if (s.ct == 0) {
            q = m;
        }

        if (s.v.size() == 1) {
            return 1;
        }

        long rs = 0;
        for (int i=0; i<s.v.size(); i++) {
            if (s.p == null || s.v.get(i).in != s.p.in) {
                s.v.get(i).p = s;
                rs += r(s.v.get(i), q);
            }
        }
        return rs;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = sc.nextInt();
        m = sc.nextInt();

        int c[] = new int[n];

        for (int i=0; i<n; i++) {
            c[i] = sc.nextInt();
        }

        CF321C g[] = new CF321C[n];

        for (int i=0; i<n; i++) {
            g[i] = new CF321C();
            g[i].in = i+1;
            g[i].ct = c[i];
        }

        for (int i=0; i<n-1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            g[a-1].v.add(g[b-1]);
            g[b-1].v.add(g[a-1]);
        }

        out.println(r(g[0], m));

        out.close();
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class BB
{

   static class item {
       ArrayList<Integer>ar=new ArrayList<Integer>();
        int cats;
        boolean visited=false;

        public item(int cats) {
            this.cats = cats;
        }

    }
   static int n,m;
   static item[]a;
public static void main(String[] args)
{

    FastScanner sc= new FastScanner(System.in);

     n=sc.nextInt();
     m=sc.nextInt();
    a=new item[n+1];
    for (int i = 1; i <= n; i++) {
        a[i]=new item(sc.nextInt());

    }
    for (int i = 1; i <= n-1; i++) {
        int x1=sc.nextInt();
        int x2=sc.nextInt();
        //System.out.println(x1+":"+x2);
        a[x1].ar.add(x2);
        a[x2].ar.add(x1);

    }

    System.out.println(dfs(1, a[1].cats));

}

static int  dfs(int i,int sum){

    if(a[i].visited)
        return 0;
        else
        a[i].visited=true;

   // System.out.println("sum"+sum);
    if(sum>m){
        return 0;
    }

    if(a[i].ar.size()==1&&a[a[i].ar.get(0)].visited)
        return 1;

    int res=0;
    for (int j = 0; j < a[i].ar.size(); j++) {
        if(!a[a[i].ar.get(j)].visited)
        {

            res+= dfs(a[i].ar.get(j),(a[a[i].ar.get(j)].cats==1)?sum+1:0);
           // System.out.println(a[i].ar.get(j)+":res:"+res);
        }
    }

        return res;
}

static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);

                        }
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

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

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

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

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class BB
{

   static class item {
       ArrayList<Integer>ar=new ArrayList<Integer>();
        int cats;
        boolean visited=false;

        public item(int cats) {
            this.cats = cats;
        }

    }
   static int n,m;
   static item[]a;
public static void main(String[] args)
{

    FastScanner sc= new FastScanner(System.in);

     n=sc.nextInt();
     m=sc.nextInt();
    a=new item[n+1];
    for (int i = 1; i <= n; i++) {
        a[i]=new item(sc.nextInt());

    }
    for (int i = 1; i <= n-1; i++) {
        int x1=sc.nextInt();
        int x2=sc.nextInt();
        //System.out.println(x1+":"+x2);
        a[x1].ar.add(x2);
        a[x2].ar.add(x1);

    }

    System.out.println(dfs(1, a[1].cats));

}

static int  dfs(int i,int sum){

    if(a[i].visited)
        return 0;
        else
        a[i].visited=true;

    if(sum>m){
        return 0;
    }

    if(a[i].ar.size()==1)
        return 1;

    int res=0;
    for (int j = 0; j < a[i].ar.size(); j++) {
        if(!a[a[i].ar.get(j)].visited)
        {

            res+= dfs(a[i].ar.get(j),(a[a[i].ar.get(j)].cats==1)?sum+1:0);
           // System.out.println(a[i].ar.get(j)+":res:"+res);
        }
    }

        return res;
}

static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);

                        }
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

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

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

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

}


import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.TreeSet;

public class Solution
{
    public static void main(String[] args) {
        new Solution().solve();
    }
    PrintWriter out;

    //long mod=1000000007L ;
    public void solve()
    {

        out=new PrintWriter(System.out);
        int n=in.nextInt();
        int m=in.nextInt();
        ver[] arr=new ver[n+1];
        for(int i=1;i<=n;i++)
        {
            arr[i]=new ver(i,in.nextInt());
        }
        for(int i=0;i<n-1;i++)
        {
            int x=in.nextInt();
            int y=in.nextInt();
            arr[x].list.add(arr[y]);
            arr[y].list.add(arr[x]);
        }

        ArrayList<ver> l=new ArrayList<ver>();
        l.add(arr[1]);
        arr[1].lbl=arr[1].c;
        arr[1].b=true;
        int ans=0;
        while(!l.isEmpty())
        {
            ArrayList<ver> l1=new ArrayList<>();
            for(ver v:l)
            {
                if(v.list.size()==1 && v.list.get(0).b==true)
                {
                    ans++;
                }
                for(ver v1:v.list)
                {
                    if(!v1.b)
                    {
                        v1.b=true;
                        if(v1.c==1)
                            v1.lbl=v.lbl+1;
                        if(v1.lbl<=m)
                        {
                            l1.add(v1);
                        }
                    }
                }

            }
            l=l1;
        }
        System.out.println(ans);
        out.close();
    }

    public class ver
    {
        int idx;
        ArrayList<ver> list=new ArrayList<ver>();
        int lbl;
        int c;
        boolean b;
        public ver(int idx,int c)
        {
            this.idx=idx;
            this.c=c;
        }
    }

    public class  ss implements Comparable<ss>
    {
        int mon;
        int f;
        public ss(int v,int f)
        {
            this.mon=v;
            this.f=f;
        }
        @Override
        public int compareTo(ss o) {

            return Integer.compare(this.mon, o.mon);
        }

        public boolean equals(Object o)
        {
            if(o==null)
            {
                return false;
            }
            else
            {
                ss oo=(ss) o;
                if(this.mon==oo.mon)
                {
                    return true;
                }
            }
            return false;
        }
    }

    public class UF {

        private int[] parent;  // parent[i] = parent of i
        private byte[] rank;   // rank[i] = rank of subtree rooted at i (never more than 31)
        private int count;
        int[] seg;
        int max;
        // number of components
        public UF(int N) {
            if (N < 0) throw new IllegalArgumentException();
            count = N;
            parent = new int[N];
            rank = new byte[N];
            seg=new int[N];
            for (int i = 0; i < N; i++) {
                parent[i] = i;
                rank[i] = 0;
                seg[i]=1;
            }
            max=1;
        }

        public int find(int p) {
            if (p < 0 || p >= parent.length) throw new IndexOutOfBoundsException();
            while (p != parent[p]) {
                parent[p] = parent[parent[p]];    // path compression by halving
                p = parent[p];
            }
            return p;
        }

        public int count() {
            return count;
        }

        public boolean connected(int p, int q) {
            return find(p) == find(q);
        }

        public boolean union(int p, int q) {
            //  System.out.println("uf "+p+" "+q);
            int rootP = find(p);
            int rootQ = find(q);
            if (rootP == rootQ) return false;

            // make root of smaller rank point to root of larger rank
            if      (rank[rootP] < rank[rootQ])
            {
                parent[rootP] = rootQ;
                seg[rootQ]+=seg[rootP];
                max=Math.max(seg[rootQ],max);
            }
            else if (rank[rootP] > rank[rootQ])
            {
                parent[rootQ] = rootP;
                seg[rootP]+=seg[rootQ];
                max=Math.max(seg[rootP],max);
            }
            else {
                parent[rootQ] = rootP;
                rank[rootP]++;
                seg[rootP]+=seg[rootQ];
                max=Math.max(seg[rootP],max);
            }
            count--;
            return true;
        }

    }

    class segTree
    {
        //  int N =(int) 1e5; // limit for array size
        int n;  // array size
        long[] sum;

        public segTree(long[] arr)
        {
            n=arr.length;
            sum=new long[3*n];
            for(int i=0;i<arr.length;i++)
            {
                sum[i+n]=arr[i];
            }
            build();
            //          for(int i=0;i<2*arr.length;i++)
            //          {
            //              System.out.print(max[i]+" ");
            //          }
            //          System.out.println();
            //          for(int i=0;i<2*arr.length;i++)
            //          {
            //              System.out.print(count[i]+" ");
            //          }
            //  System.out.println(Arrays.toString(max)+" "+Arrays.toString(count));
        }
        void build() {  // build the tree
            for (int i = n - 1; i > 0; --i)
            {
                if(sum[i<<1]!=sum[i<<1|1])
                {
                    sum[i] =sum[i<<1] | sum[i<<1|1];
                }
                else
                {
                    sum[i]=sum[i<<1];
                }
            }
        }

        void modify(int p, int value) {  // set value at position p
            for (sum[p += n] = value; p > 1; p >>= 1) sum[p>>1] = sum[p] | sum[p^1];
        }

        long query(int l, int r) {  // sum on interval [l, r)
            //  System.out.println(Arrays.toString(sum)+" "+l+" "+ r);
            long ans=0L;
            for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
                if ((l&1)!=0)
                {
                    ans|=sum[l];
                    l++;
                }
                if ((r&1)!=0)
                {
                    --r;
                    ans|=sum[r];
                }
            }
            return ans;
        }
    }

    class qq implements Comparable<qq>
    {
        long sqrn;
        int l,r;
        int idx;
        public qq(int idx,int l,int r)
        {
            this.l=l;
            this.idx=idx;
            this.r=r;
        }

        @Override
        public int compareTo(qq o) {
            // TODO Auto-generated method stub
            if(this.l/sqrn==o.l/sqrn)
            {
                return Integer.compare(this.r, o.r);
            }
            else
            {
                return Integer.compare(this.l,o.l);
            }
        }

        public String toString()
        {
            return "{ "+this.idx+" "+this.l+" "+this.r+" }";
        }

    }

    //  public void add(int x)
    //  {
    //      System.out.println("Add "+x);
    //      count[arr[x]]++;
    //      if(count[arr[x]]==c)
    //      {
    //          for(int i=0;i<3;i++)
    //          {
    //              if(s[i]==-1)
    //              {
    //                  answer++;
    //                  s[i]=arr[x];
    //                  break;
    //              }
    //          }
    //      }
    //      else if(count[arr[x]]>c)
    //      {
    //          if(s[0]!=arr[x] && s[1]!=arr[x] && s[2]!=arr[x])
    //          {
    //              for(int i=0;i<3;i++)
    //              {
    //                  if(s[i]==-1)
    //                  {
    //                      answer++;
    //                      s[i]=arr[x];
    //                      break;
    //                  }
    //              }
    //          }
    //      }
    //  for(int i=0;i<10;i++)
    //  {
    //      System.out.print(count[i]+" ");
    //  }
    //  System.out.println();
    //      System.out.println(answer);
    //  }
    //
    //  public void remove(int x)
    //  {
    //      count[arr[x]]--;
    //      System.out.println("remove " +x);
    //      if(count[arr[x]]==c-1)
    //      {
    //          for(int i=0;i<3;i++)
    //          {
    //              if(s[i]==arr[x])
    //              {
    //                  answer--;
    //                  s[i]=-1;
    //                  break;
    //              }
    //          }
    //      }
    //      else if(count[arr[x]]>c)
    //      {
    //          if(s[0]!=arr[x] && s[1]!=arr[x] && s[2]!=arr[x])
    //          {
    //              for(int i=0;i<3;i++)
    //              {
    //                  if(s[i]==-1)
    //                  {
    //                      answer++;
    //                      s[i]=arr[x];
    //                      break;
    //                  }
    //              }
    //          }
    //      }
    //      for(int i=0;i<10;i++)
    //      {
    //          System.out.print(count[i]+" ");
    //      }
    //      System.out.println();
    //      System.out.println(answer);
    //  }

    //
    //      long pow(long a,int n,long m)
    //      {
    //          if(n==1)
    //              return a;
    //          if(n==0)
    //              return 1;
    //          long ans=pow(a,n/2,m);
    //          ans*=ans;
    //          ans%=m;
    //          if(n%2!=0)
    //              ans*=a;
    //          ans%=m;
    //          return ans;
    //      }

    public static int gcd(long a, long b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.intValue();
    }

    FasterScanner in=new FasterScanner();

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

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

        public String nextString() {
            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 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 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 int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

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


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        Node[] node = new Node[n];
        for (int i = 0; i < n; i++) {
            node[i] = new Node( in.nextInt() );
        }

        for (int i = 0; i < n - 1; i++) {
            int f = in.nextInt() - 1;
            int t = in.nextInt() - 1;
            node[f].adjacent.add(node[t]);
        }

        System.out.println( C.dfs(node[0], 0, m) );

    }

    public static int dfs(Node n, int c, int m) {
        if (n.c == 1) {
            if (++c > m) return 0;
        } else {
            c = 0;
        }
        /*
        if (n.adjacent.size() == 0) {
            return 1;
        }
        */
        boolean isLeaf = true;
        int tot_rest = 0;
        for (Node a : n.adjacent) {
            if (a == n) continue;
            isLeaf = false;
            tot_rest += dfs(a, c, m);
        }
        if (isLeaf) return 1;
        return tot_rest;
    }

    public static class Node {
        int c;
        ArrayList<Node> adjacent;
        public Node(int c) {
            this.adjacent = new ArrayList<Node>();
            this.c = c;
        }
    }
}


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        Node[] node = new Node[n];
        for (int i = 0; i < n; i++) {
            node[i] = new Node( in.nextInt() );
        }

        for (int i = 0; i < n - 1; i++) {
            int f = in.nextInt() - 1;
            int t = in.nextInt() - 1;
            node[f].adjacent.add(node[t]);
            node[t].adjacent.add(node[f]);
        }

        System.out.println( C.dfs(node[0], 0, m) );

    }

    public static int dfs(Node n, int c, int m) {

        n.visited = true;

        if (n.c == 1) {
            if (++c > m) return 0;
        } else {
            c = 0;
        }
        /*
        if (n.adjacent.size() == 0) {
            return 1;
        }
        */
        int tot_rest = 0;
        boolean isLeaf = true;
        for (Node a : n.adjacent) {
            if (a.visited) continue;
            isLeaf = false;
            tot_rest += dfs(a, c, m);
        }
        if (isLeaf) return 1;
        return tot_rest;
    }

    public static class Node {
        int c;
        ArrayList<Node> adjacent;
        boolean visited;
        public Node(int c) {
            this.adjacent = new ArrayList<Node>();
            this.c = c;
            this.visited = false;
        }
    }
}


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        Node[] node = new Node[n];
        for (int i = 0; i < n; i++) {
            node[i] = new Node( in.nextInt() );
        }

        for (int i = 0; i < n - 1; i++) {
            int f = in.nextInt() - 1;
            int t = in.nextInt() - 1;
            node[f].adjacent.add(node[t]);
        }

        System.out.println( C.dfs(node[0], 0, m) );

    }

    public static int dfs(Node n, int c, int m) {
        if (n.c == 1) {
            c++;
        } else {
            c = 0;
        }
        if (c > m) return 0;
        if (n.adjacent.size() == 0) {
            return 1;
        }
        int tot_cats = 0;
        for (Node a : n.adjacent) {
            tot_cats += dfs(a, c, m);
        }
        return tot_cats;
    }

    public static class Node {
        int c;
        ArrayList<Node> adjacent;
        public Node(int c) {
            this.adjacent = new ArrayList<Node>();
            this.c = c;
        }
    }
}


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        Node[] node = new Node[n];
        for (int i = 0; i < n; i++) {
            node[i] = new Node( in.nextInt() );
        }

        for (int i = 0; i < n - 1; i++) {
            int f = in.nextInt() - 1;
            int t = in.nextInt() - 1;
            node[f].adjacent.add(node[t]);
        }

        System.out.println( C.dfs(node[0], 0, m) );

    }

    public static int dfs(Node n, int c, int m) {
        if (n.c == 1) {
            if (++c > m) return 0;
        } else {
            c = 0;
        }
        /*
        if (n.adjacent.size() == 0) {
            return 1;
        }
        */
        boolean isLeaf = true;
        int tot_rest = 0;
        for (Node a : n.adjacent) {
            if (a.visited) continue;
            isLeaf = false;
            a.visited = true;
            tot_rest += dfs(a, c, m);
        }
        if (isLeaf) return 1;
        return tot_rest;
    }

    public static class Node {
        int c;
        ArrayList<Node> adjacent;
        boolean visited;
        public Node(int c) {
            this.adjacent = new ArrayList<Node>();
            this.c = c;
            this.visited = false;
        }
    }
}