#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];
int cnt[maxn];
vector <pair<int, int> > G;

/*ll find(int v)
{

  if (used[v][k]) {
    return F[v][k];
  }
  used[v][k] = 1;

  if (k == 0) {
    return F[v][k] = 1;
  }

  ll res = 0;
  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i], v, k - 1);
    }
  }

  return F[v][k] = res;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i]);
    }
  }

}*/

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }

  F[v][0] = 1;
  for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        if (i) {
          F[v][i] += F[A[v][j]][i - 1];
        }

      }
    }
  }
}

int main()
{
  //ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  G.reserve(n);

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    //cin >> v >> u;
    --v, --u;
    /*A[v].pb(u);
    A[u].pb(v);*/
    G.pb(mp(v, u));
    ++cnt[v];
    ++cnt[u];
  }

  for (int i = 0; i < n; ++i) {
    A[i].reserve(cnt[i]);
  }

  for (int i = 0; i < sz(G); ++i) {
    A[G[i].fi].pb(G[i].se);
    A[G[i].se].pb(G[i].fi);
  }

  dfs(0, -1);

  /*for (int v = 0; v < n; ++v) {
    for (int i = 0; i <= k; ++i) {
      find(v, P[v], i);
    }
  }*/
  //find(0);

  for (int v = 0; v < n; ++v) {
    res += (F[v][k]);
    memset(sum, 0, sizeof(sum));

    /*for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          sum[i] += F[A[v][j]][i];
        }
      }
    }
    */
    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {

          res += sum[i] * F[A[v][j]][k - 2 - i];
          sum[i] += F[A[v][j]][i];
        }
      }
    }
  }

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];

ll find(int v, int p, int k)
{

  if (used[v][k]) {
    return F[v][k];
  }
  used[v][k] = 1;

  if (k == 0) {
    return F[v][k] = 1;
  }

  ll res = 0;
  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i], v, k - 1);
    }
  }

  return F[v][k] = res;
}

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }
}

int main()
{
  ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    //scanf("%d%d", &v, &u);
    cin >> v >> u;
    --v, --u;
    A[v].pb(u);
    A[u].pb(v);
  }

  dfs(0, -1);

  for (int v = 0; v < n; ++v) {
    for (int i = 0; i <= k; ++i) {
      find(v, P[v], i);
    }
  }

  for (int v = 0; v < n; ++v) {
    res += (F[v][k] << 1);
    memset(sum, 0, sizeof(sum));

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          sum[i] += F[A[v][j]][i];
        }
      }
    }

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          res += (sum[i] - F[A[v][j]][i]) * F[A[v][j]][k - 2 - i];
        }
      }
    }
  }

  res >>= 1;

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];
int cnt[maxn];
vector <pair<int, int> > G;

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }

  F[v][0] = 1;
  for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        if (i) {
          F[v][i] += F[A[v][j]][i - 1];
        }

      }
    }

    if (!F[v][i]) {
      break;
    }
  }
}

int main()
{
  //ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  G.reserve(n);

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v, --u;

    G.pb(mp(v, u));
    ++cnt[v];
    ++cnt[u];
  }

  for (int i = 0; i < n; ++i) {
    A[i].reserve(cnt[i]);
  }

  for (int i = 0; i < sz(G); ++i) {
    A[G[i].fi].pb(G[i].se);
    A[G[i].se].pb(G[i].fi);
  }

  dfs(0, -1);

  for (int v = 0; v < n; ++v) {
    res += (F[v][k]);
    memset(sum, 0, sizeof(sum));

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {

          res += sum[i] * F[A[v][j]][k - 2 - i];
          sum[i] += F[A[v][j]][i];
        }
      }
    }
  }

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];
int cnt[maxn];
vector <pair<int, int> > G;

ll find(int v, int p, int k)
{

  if (used[v][k]) {
    return F[v][k];
  }
  used[v][k] = 1;

  if (k == 0) {
    return F[v][k] = 1;
  }

  ll res = 0;
  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i], v, k - 1);
    }
  }

  return F[v][k] = res;
}

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }
}

int main()
{
  //ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  G.reserve(n);

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    //cin >> v >> u;
    --v, --u;
    /*A[v].pb(u);
    A[u].pb(v);*/
    G.pb(mp(v, u));
    ++cnt[v];
    ++cnt[u];
  }

  for (int i = 0; i < n; ++i) {
    A[i].reserve(cnt[i]);
  }

  for (int i = 0; i < sz(G); ++i) {
    A[G[i].fi].pb(G[i].se);
    A[G[i].se].pb(G[i].fi);
  }

  dfs(0, -1);

  for (int v = 0; v < n; ++v) {
    for (int i = 0; i <= k; ++i) {
      find(v, P[v], i);
    }
  }

  for (int v = 0; v < n; ++v) {
    res += (F[v][k]);
    memset(sum, 0, sizeof(sum));

    /*for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          sum[i] += F[A[v][j]][i];
        }
      }
    }
    */
    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {

          res += sum[i] * F[A[v][j]][k - 2 - i];
          sum[i] += F[A[v][j]][i];
        }
      }
    }
  }

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];

ll find(int v, int p, int k)
{

  if (used[v][k]) {
    return F[v][k];
  }
  used[v][k] = 1;

  if (k == 0) {
    return F[v][k] = 1;
  }

  ll res = 0;
  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i], v, k - 1);
    }
  }

  return F[v][k] = res;
}

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }
}

int main()
{
  //ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    //cin >> v >> u;
    --v, --u;
    A[v].pb(u);
    A[u].pb(v);
  }

  dfs(0, -1);

  for (int v = 0; v < n; ++v) {
    for (int i = 0; i <= k; ++i) {
      find(v, P[v], i);
    }
  }

  for (int v = 0; v < n; ++v) {
    res += (F[v][k] << 1);
    memset(sum, 0, sizeof(sum));

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          sum[i] += F[A[v][j]][i];
        }
      }
    }

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          res += (sum[i] - F[A[v][j]][i]) * F[A[v][j]][k - 2 - i];
        }
      }
    }
  }

  res >>= 1;

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];

ll find(int v, int p, int k)
{

  if (used[v][k]) {
    return F[v][k];
  }
  used[v][k] = 1;

  if (k == 0) {
    return F[v][k] = 1;
  }

  ll res = 0;
  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i], v, k - 1);
    }
  }

  return F[v][k] = res;
}

void dfs(int v, int p)
{
  P[v] = p;

  memset(sum, 0, sizeof(sum));
  for (int i = 0; i <= k - 2; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        if (used[A[v][j]][i]) {
          sum[i] += F[A[v][j]][i];
        }
        else {
          sum[i] += find(A[v][j], v, i);
        }
      }
    }
  }

  for (int i = 0; i <= k - 2; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        res += (sum[i] - F[A[v][j]][i]) * F[A[v][j]][k - 2 - i];
      }
    }
  }

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }
}

int main()
{
  ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    //scanf("%d%d", &v, &u);
    cin >> v >> u;
    --v, --u;
    A[v].pb(u);
    A[u].pb(v);
  }

  dfs(0, -1);

  res /= 2;

  for (int i = 0; i < n; ++i) {
    res += find(i, P[i], k);
  }

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];
int cnt[maxn];
vector <pair<int, int> > G;

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }

  F[v][0] = 1;
  /*for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        if (i) {
          F[v][i] += F[A[v][j]][i - 1];
        }

      }
    }

    if (!F[v][i]) {
      break;
    }
  }
  */

  for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        if (i) {
          F[v][i] += F[A[v][j]][i - 1];
        }

      }
    }

  }
}

int main()
{
  //ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  G.reserve(n);

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v, --u;

    G.pb(mp(v, u));
    ++cnt[v];
    ++cnt[u];
  }

  for (int i = 0; i < n; ++i) {
    A[i].reserve(cnt[i]);
  }

  for (int i = 0; i < sz(G); ++i) {
    A[G[i].fi].pb(G[i].se);
    A[G[i].se].pb(G[i].fi);
  }

  dfs(0, -1);

  for (int v = 0; v < n; ++v) {
    res += (F[v][k]);
    memset(sum, 0, sizeof(sum));

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {

          res += sum[i] * F[A[v][j]][k - 2 - i];
          sum[i] += F[A[v][j]][i];
        }
      }
    }
  }

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];
int cnt[maxn];
vector <pair<int, int> > G;

ll find(int v, int p, int k)
{

  if (used[v][k]) {
    return F[v][k];
  }
  used[v][k] = 1;

  if (k == 0) {
    return F[v][k] = 1;
  }

  ll res = 0;
  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i], v, k - 1);
    }
  }

  return F[v][k] = res;
}

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }
}

int main()
{
  //ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  G.reserve(n);

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    //cin >> v >> u;
    --v, --u;
    /*A[v].pb(u);
    A[u].pb(v);*/
    G.pb(mp(v, u));
    ++cnt[v];
    ++cnt[u];
  }

  for (int i = 0; i < n; ++i) {
    A[i].reserve(cnt[i]);
  }

  for (int i = 0; i < sz(G); ++i) {
    A[G[i].fi].pb(G[i].se);
    A[G[i].se].pb(G[i].fi);
  }

  dfs(0, -1);

  for (int v = 0; v < n; ++v) {
    for (int i = 0; i <= k; ++i) {
      find(v, P[v], i);
    }
  }

  for (int v = 0; v < n; ++v) {
    res += (F[v][k] << 1);
    memset(sum, 0, sizeof(sum));

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          sum[i] += F[A[v][j]][i];
        }
      }
    }

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {
          res += (sum[i] - F[A[v][j]][i]) * F[A[v][j]][k - 2 - i];
        }
      }
    }
  }

  res >>= 1;

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];
int cnt[maxn];
vector <pair<int, int> > G;

void dfs(int v, int p)
{
  P[v] = p;

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }

  F[v][0] = 1;
  /*for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        if (i) {
          F[v][i] += F[A[v][j]][i - 1];
        }

      }
    }

    if (!F[v][i]) {
      break;
    }
  }
  */

  for (int j = 0; j < sz(A[v]); ++j) {
    for (int i = 1; i <= k; ++i) {
      if (A[v][j] != p) {
        if (i) {
          F[v][i] += F[A[v][j]][i - 1];
        }

      }
    }

  }
}

int main()
{
  //ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

  G.reserve(n);

  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v, --u;

    G.pb(mp(v, u));
    ++cnt[v];
    ++cnt[u];
  }

  for (int i = 0; i < n; ++i) {
    A[i].reserve(cnt[i]);
  }

  for (int i = 0; i < sz(G); ++i) {
    A[G[i].fi].pb(G[i].se);
    A[G[i].se].pb(G[i].fi);
  }

  dfs(0, -1);

  for (int v = 0; v < n; ++v) {
    res += (F[v][k]);
    memset(sum, 0, sizeof(sum));

    for (int i = 0; i <= k - 2; ++i) {
      for (int j = 0; j < sz(A[v]); ++j) {
        if (A[v][j] != P[v]) {

          res += sum[i] * F[A[v][j]][k - 2 - i];
          sum[i] += F[A[v][j]][i];
        }
      }
    }
  }

  cout << res << "\n";

  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll res = 0;
int k;

const int maxn = 50 * 1000 + 5;
const int maxk = 500 + 5;

ll F[maxn][maxk];
bool used[maxn][maxk];
vector <int> A[maxn];
int P[maxn];
ll sum[maxk];

ll find(int v, int p, int k)
{
  if (k == 0) {
    return 1;
  }

  if (used[v][k]) {
    return F[v][k];
  }
  used[v][k] = 1;

  ll res = 0;
  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      res += find(A[v][i], v, k - 1);
    }
  }

  return F[v][k] = res;
}

void dfs(int v, int p)
{
  P[v] = p;

  memset(sum, 0, sizeof(sum));
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        sum[i] += find(A[v][j], v, i);
      }
    }
  }

  for (int i = 0; i <= k - 2; ++i) {
    for (int j = 0; j < sz(A[v]); ++j) {
      if (A[v][j] != p) {
        res += (sum[i] - find(A[v][j], v, i)) * find(A[v][j], v, k - 2 - i);
      }
    }
  }

  for (int i = 0; i < sz(A[v]); ++i) {
    if (A[v][i] != p) {
      dfs(A[v][i], v);
    }
  }
}

int main()
{
  ios::sync_with_stdio(0);

  int n;
  cin >> n >> k;

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

  dfs(0, -1);

  res /= 2;

  for (int i = 0; i < n; ++i) {
    res += find(i, P[i], k);
  }

  cout << res << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        ans[v] += dp[path[i]][k - (l - i - 1)] - dp[v][max(0 , k - 2*(l - i - 1))];
        if (k - (l - i -1) == 0)
            ans[v]++;
    }
    out += ans[v];
    //cerr << v << " : " <<dp[v][k] << " " << ans[v]<<endl;
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
    {
        dp[i][0] = 1;
    }
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 3 - k) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 3 - k) ; i--)
    {
        ans[v] += dp[path[i]][k - (l - i - 1)] - dp[v][k - 2*(l - i - 1)];
    }
    out += ans[v];
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 0 ; i <= n ; i++)
        dp[i][0] = 1;
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - maxk) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        ans[v] += dp[path[i]][k - (l - i - 1)] - dp[path[i+1]][max(0 , k - (l - i - 1)-1)];
        if (k - (l - i -1) == 0)
            ans[v]++;
        else if(k - (l - i - 1) - 1 == 0)
            ans[v]--;
    }
    out += ans[v];
    //cerr << v << " : " <<dp[v][k] << " " << ans[v]<<endl;
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
    {
        dp[i][0] = 0;
    }
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int  k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    int l = path.size();
    //cerr << v << " : " <<dp[v][k] << " " << ans[v]<<endl;
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        for (int x = 2 ; x <= k - 1 ; x++)
        {
            out += dp[u][x-1]*(dp[v][k - x] - dp[u][k - x - 1]);
        }

        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    out/=2;
    for (int i = 1 ; i <= n ; i++)
        out += dp[i][k];
    cout << out;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005;
int k , n;
int d[maxn];
vector<int> adj[maxn];
bool mark[maxn] , m2[maxn];
deque<int> b;
long long ans = 0;

void BFS(int v)
{
    mark[v] = true;
    d[v] = 0;
    b.push_back(v);
    while (!b.empty())
    {
        if (d[b.front()]==k)
            break;
        int w = b.front();
        //cerr << w << " " << d[w] << endl;
        for (int i = 0 ; i < adj[w].size() ; i++)
        {
            int u = adj[w][i];
            if (!mark[u])
            {
                mark[u] = true;
                b.push_back(u);
                d[u] = d[w] + 1;
                if (d[u] == k)
                    ans++;
            }
        }
        b.pop_front();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1; i <= n ; i++)
    {
        //cerr<<"--------"<< endl;
        BFS(i);
        //m2[i]= true;
        b.clear();
        for (int i = 1; i<= n ; i++)
        {
            mark[i] = 0;
        }
    }
    cout << ans/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int  k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - maxk) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        ans[v] += dp[path[i]][k - (l - i - 1)] - dp[path[i+1]][max(0 , k - (l - i - 1)-1)];
        if (k - (l - i -1) == 0)
            ans[v]++;
        else if(k - (l-i-1) == 1)
            ans[v]--;
    }
    out += ans[v];
    //cerr << v << " : " <<dp[v][k] << " " << ans[v]<<endl;
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
    {
        dp[i][0] = 0;
    }
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        ans[v] += max( (long long)0, dp[path[i]][k - (l - i - 1)] - dp[v][max(0 , k - 2*(l - i - 1))]);
    }
    out += ans[v];
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
    {
        dp[i][0] = 1;
    }
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005;
int k , n;
int d[maxn];
vector<int> adj[maxn];
bool mark[maxn];
int par[maxn];
deque<int> b;
long long ans = 0;

void BFS(int v)
{
    d[v] = 0;
    par[v] = v;
    b.push_back(v);

    while (!b.empty())
    {
        if (d[b.front()]==k)
        {
            return;
        }
        int w = b.front();
        //cerr << w << " " << d[w] << endl;
        for (int i = 0 ; i < adj[w].size() ; i++)
        {
            int u = adj[w][i];
            if (u != par[w])
            {
                par[u] = w;
                b.push_back(u);
                d[u] = d[w] + 1;
                if (d[u] == k)
                    ans++;
            }
        }
        b.pop_front();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1; i <= n ; i++)
    {
        //cerr<<"--------"<< endl;
        par[i] = i;
        BFS(i);
        //m2[i]= true;
        b.clear();
    }
    cout << ans/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        ans[v] += max( (long long)0, dp[path[i]][k - (l - i - 1)] - dp[v][max(0 , k - 2*(l - i - 1))]);
    }
    out += ans[v];
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
    {
        dp[i][0] = 1;
    }
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 5 - k) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        ans[v] += dp[path[i]][k - (l - i - 1)] - dp[v][max(0 , k - 2*(l - i - 1))];
        if (k - (l - i -1) == 0)
            ans[v]++;
    }
    out += ans[v];
    //cerr << v << " : " <<dp[v][k] << " " << ans[v]<<endl;
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
    {
        dp[i][0] = 1;
    }
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 3 - maxk) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 3 - maxk) ; i--)
    {
        ans[v] += dp[path[i]][k - (l - i - 1)] - dp[v][k - 2*(l - i - 1)];
    }
    out += ans[v];
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int  k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    int l = path.size();
    //cerr << v << " : " <<dp[v][k] << " " << ans[v]<<endl;
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        for (int x = 1 ; x <= k - 1 ; x++)
        {
            out += dp[u][x-1]*(dp[v][k - x] - dp[u][k - x - 1]);
        }

        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
        dp[i][0] = 1;

    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    out/=2;
    for (int i = 1 ; i <= n ; i++)
        out += dp[i][k];
    cout << out;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50005 , maxk = 505;
int  k , n;
long long dp[maxn][maxk] , ans[maxn];
vector<int> adj[maxn] , path;
long long out;

void Dfs(int v = 1, int par = 1)
{
    int l = path.size();
    for(int i = l - 2; i >= max(0 , l - 1 - maxk) ; i--)
    {
        dp[path[i]][l - i -1]++;
    }
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs(u , v);
        path.pop_back();
    }
}

void Dfs2(int v = 1, int par = 1)
{
    //cerr << v << endl;
    int l = path.size();
    ans[v] = dp[v][k];
    for(int i = l - 2; i >= max(0 , l - 1 - k) ; i--)
    {
        ans[v] += dp[path[i]][k - (l - i - 1)] - dp[path[i+1]][max(0 , k - (l - i - 1)-1)];
        if (k - (l - i -1) == 0)
            ans[v]++;
    }
    out += ans[v];
    //cerr << v << " : " <<dp[v][k] << " " << ans[v]<<endl;
    for (int i = 0 ; i < adj[v].size(); i++)
    {
        int u = adj[v][i];
        if (u == par)
            continue;
        path.push_back(u);
        Dfs2(u , v);
        path.pop_back();
    }
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for (int i = 0 ; i < n -1 ; i++)
    {
        int v , w;
        cin >> v >> w;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    for (int i = 1 ; i <= n ; i++)
    {
        dp[i][0] = 1;
    }
    path.push_back(1);
    Dfs();
    path.clear();
    path.push_back(1);
    Dfs2();

    cout << out/2;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
long long b[100005],d[50002],c[50001],x=50000,y;
int a[50001],f[50001],step=1;
main()
{
    int i,j,k,n,l,m,p,q,r,e,g;
    cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }
    queue<int> q1,q2;
    for(j=1;j<=n;j++) if(v[j].size()==1)
    {u.push_back(j); a[j]=1; break;}
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];
            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       x++;
                       r=1;
                       step++;
                       f[q]=step;
                       if(v[q].size()>2)
                       {
                           b[x]++;
                           q1.push(i);
                           f[i]=step;
                           while(!q1.empty()||!q2.empty())
                           {

                               if(r%2!=0)
                               {
                                   while(!q1.empty())
                                   {
                                g=q1.front();
                                q1.pop();
                                for(j=0;j<v[g].size();j++)
                                    if(f[v[g][j]]!=step)
                                    {q2.push(v[g][j]);f[v[g][j]]=step; b[x+r]++;  }
                                   }
                                   r++;
                               }
                               else
                               {
                                   while(!q2.empty())
                                   {
                                g=q2.front();
                                q2.pop();
                                for(j=0;j<v[g].size();j++)
                                    if(f[v[g][j]]!=step)
                                    {q1.push(v[g][j]);f[v[g][j]]=step; b[x+r]++; }
                                   }
                                   r++;
                               }
                           }
                       }
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);

                   if(a[p]==0) {x--;
                    b[x]=1;
                    //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                    y+=b[x+k-1];
                    }
                    a[p]=1;
                    c[i]++;
                }
        } cout<<y;
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[200005],d[50002],c[50001],x=100002,y,f[50002],step=1;
long long a[50001];
main()
{
    long long i,j,k,n,l,m,p,q,r,e,g,t;
    scanf("%d%d",&n,&k);
    //cin>>n>>k;
    vector<int> v[n+1],u,q1,q2;

    for(i=0; i<n-1; i++)
    {
        //cin>>l>>m;
        scanf("%d%d",&l,&m);
        v[l].push_back(m);
        v[m].push_back(l);
    }
    for(j=1; j<=n; j++) if(v[j].size()==1)
        {
            u.push_back(j);
            a[j]=1;
            break;
        }
    while(!u.empty())
    {
        i=u[u.size()-1];
        p=v[i][c[i]];
        if(c[i]>=v[i].size())
        {
            if(u.size()!=1)
            {
                q=u[u.size()-2];
                r=0;
                step++;
                f[q]=step;
                if(v[i].size()>2)
                {
                    q1.push_back(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2==0)
                        {
                            while(!q1.empty())
                            {
                                g=q1[q1.size()-1];
                                q1.pop_back();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2[q2.size()-1];
                                q2.pop_back();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
                x++;
                r=1;
                step++;
                f[q]=step;
                if(v[q].size()>2)
                {
                    b[x]++;
                    q1.push_back(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2!=0)
                        {
                            while(!q1.empty())
                            {
                                g=q1[q1.size()-1];
                                q1.pop_back();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2[q2.size()-1];
                                q2.pop_back();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
            }
            u.pop_back();
        }
        else
        {
            if(a[p]==0) u.push_back(p);
            if(a[p]==0)
            {
                x--;
                b[x]=1;
                //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                y+=b[x+k-1];
            }
            a[p]=1;
            c[i]++;
        }
    }
    //cout<<y;
    printf("%d",y); return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
long long b[100005],d[50002],c[50001],x=50000,y,f[50002],step=1;
int a[50001];
main()
{
    int i,j,k,n,l,m,p,q,r,e,g;
    scanf("%d%d",&n,&k);
    //cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0; i<n-1; i++)
    {
        //cin>>l>>m;
        scanf("%d%d",&l,&m);
        v[l].push_back(m);
        v[m].push_back(l);
    }
    queue<int> q1,q2;
    for(j=1; j<=n; j++) if(v[j].size()==1)
        {
            u.push_back(j);
            a[j]=1;
            break;
        }
    while(!u.empty())
    {
        i=u[u.size()-1];
        p=v[i][c[i]];
        if(c[i]>=v[i].size())
        {
            if(u.size()!=1)
            {
                q=u[u.size()-2];
                r=0;
                step++;
                f[q]=step;
                if(v[i].size()>2)
                {
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2==0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]--;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]--;
                                    }
                            }
                            r++;
                        }
                    }
                }
                x++;
                r=1;
                step++;
                f[q]=step;
                if(v[q].size()>2)
                {
                    b[x]++;
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2!=0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]++;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]++;
                                    }
                            }
                            r++;
                        }
                    }
                }
            }
            u.pop_back();
        }
        else
        {
            if(a[p]==0) u.push_back(p);

            if(a[p]==0)
            {
                x--;
                b[x]=1;
                //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                y+=b[x+k-1];
            }
            a[p]=1;
            c[i]++;
        }
    }
    //cout<<y;
    printf("%d\n",y);
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
int b[100005],d[50002],c[50001],x=50002,y,f[50002],step=1;
int a[50001];
main()
{
    int i,j,k,n,l,m,p,q,r,e,g;
    scanf("%d%d",&n,&k);
    //cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0; i<n-1; i++)
    {
        //cin>>l>>m;
        scanf("%d%d",&l,&m);
        v[l].push_back(m);
        v[m].push_back(l);
    }
    queue<int> q1,q2;
    for(j=1; j<=n; j++) if(v[j].size()==1)
        {
            u.push_back(j);
            a[j]=1;
            break;
        }
    while(!u.empty())
    {
        i=u[u.size()-1];
        p=v[i][c[i]];
        if(c[i]>=v[i].size())
        {
            if(u.size()!=1)
            {
                q=u[u.size()-2];
                r=0;
                step++;
                f[q]=step;
                if(v[i].size()>2)
                {
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2==0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
                x++;
                r=1;
                step++;
                f[q]=step;
                if(v[q].size()>2)
                {
                    b[x]++;
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2!=0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
            }
            u.pop_back();
        }
        else
        {
            if(a[p]==0) u.push_back(p);
            if(a[p]==0)
            {
                x--;
                b[x]=1;
                //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                y+=b[x+k-1];
            }
            a[p]=1;
            c[i]++;
        }
    }
    //cout<<y;
    printf("%d\n",y);
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
int b[100005],d[50002],c[50001],x=50002,y,f[50002],step=1;
int a[50001];
main()
{
    int i,j,k,n,l,m,p,q,r,e,g,t;
    scanf("%d%d",&n,&k);
    //cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0; i<n-1; i++)
    {
        //cin>>l>>m;
        scanf("%d%d",&l,&m);
        v[l].push_back(m);
        v[m].push_back(l);
    }
    queue<int> q1,q2;
    for(j=1; j<=n; j++) if(v[j].size()==1)
        {
            u.push_back(j);
            a[j]=1;
            break;
        }
    while(!u.empty())
    {
        i=u[u.size()-1];
        p=v[i][c[i]];
        if(c[i]>=v[i].size())
        {
            if(u.size()!=1)
            {
                q=u[u.size()-2];
                r=0;
                step++;
                f[q]=step;
                if(v[i].size()>2)
                {
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2==0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
                x++;
                r=1;
                step++;
                f[q]=step;
                if(v[q].size()>2)
                {
                    b[x]++;
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2!=0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
            }
            u.pop_back();
        }
        else
        {
            if(a[p]==0) u.push_back(p);
            if(a[p]==0)
            {
                x--;
                b[x]=1;
                //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                y+=b[x+k-1];
            }
            a[p]=1;
            c[i]++;
        }
    }
    //cout<<y;
    printf("%d\n",y);
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[50000][500],d;
int a[500],c[50000];
main()
{
    int i,j,k,n,l,m,p,q,s;
    cin>>n>>k;
    vector<int> v[n+1],u,w;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }

    u.push_back(1); a[1]=1;
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];

            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       b[q][0]=1;
                       b[i][0]=1;

                       for(j=0;j<k;j++)
                       d+=b[q][j]*b[i][k-j-1];

                       for(j=1;j<=k-1;j++)
                       b[q][j]+=b[i][j-1];
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);
                    a[p]=1;
                    c[i]++;
                }
        }

    cout<<d;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
int b[100005],d[50002],c[50001],x=50000,y,f[50002],step=1;
int a[50001];
main()
{
    int i,j,k,n,l,m,p,q,r,e,g;
    scanf("%d%d",&n,&k);
    //cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0; i<n-1; i++)
    {
        //cin>>l>>m;
        scanf("%d%d",&l,&m);
        v[l].push_back(m);
        v[m].push_back(l);
    }
    queue<int> q1,q2;
    for(j=1; j<=n; j++) if(v[j].size()==1)
        {
            u.push_back(j);
            a[j]=1;
            break;
        }
    while(!u.empty())
    {
        i=u[u.size()-1];
        p=v[i][c[i]];
        if(c[i]>=v[i].size())
        {
            if(u.size()!=1)
            {
                q=u[u.size()-2];
                r=0;
                step++;
                f[q]=step;
                if(v[i].size()>2)
                {
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2==0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]--;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]--;
                                    }
                            }
                            r++;
                        }
                    }
                }
                x++;
                r=1;
                step++;
                f[q]=step;
                if(v[q].size()>2)
                {
                    b[x]++;
                    q1.push(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2!=0)
                        {
                            while(!q1.empty())
                            {
                                g=q1.front();
                                q1.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]++;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2.front();
                                q2.pop();
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push(v[g][j]);
                                        f[v[g][j]]=step;
                                        b[x+r]++;
                                    }
                            }
                            r++;
                        }
                    }
                }
            }
            u.pop_back();
        }
        else
        {
            if(a[p]==0) u.push_back(p);
            if(a[p]==0)
            {
                x--;
                b[x]=1;
                //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                y+=b[x+k-1];
            }
            a[p]=1;
            c[i]++;
        }
    }
    //cout<<y;
    printf("%d\n",y);
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[50000][500],d;
int a[500],c[50000];
main()
{
    int i,j,k,n,l,m,p,q;
    cin>>n>>k;
    vector<int> v[n+1],u,w;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }

    u.push_back(1); a[1]=1;
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];

            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       b[q][0]=1;
                       b[i][0]=1;

                       for(j=0;j<k;j++)
                       d+=b[q][j]*b[i][k-j-1];

                       for(j=1;j<=k-1;j++)
                       b[q][j]+=b[i][j-1];
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);
                    a[p]=1;
                    c[i]++;
                }
        }

    cout<<d;
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[50001][501],d,c[50001];
long long a[501];
main()
{
    long long i,j,k,n,l,m,p,q;
    cin>>n>>k;
    vector<long long> v[n+1],u;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }

    u.push_back(l); a[l]=1;
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];

            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       b[q][0]=1;
                       b[i][0]=1;

                       for(j=0;j<k;j++)
                       d+=b[q][j]*b[i][k-j-1];

                       for(j=1;j<=k-1;j++)
                       b[q][j]+=b[i][j-1];
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);
                    a[p]=1;
                    c[i]++;
                }
        }

    cout<<d;
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[50001][501],d,c[50001];
int a[50001];
main()
{
    int i,j,k,n,l,m,p,q;
    cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }

    u.push_back(l); a[l]=1;
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];

            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       b[q][0]=1;
                       b[i][0]=1;

                       for(j=0;j<k;j++)
                       d+=b[q][j]*b[i][k-j-1];

                       for(j=1;j<=k-1;j++)
                       b[q][j]+=b[i][j-1];
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);
                    a[p]=1;
                    c[i]++;
                }
        }

    cout<<d;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
long long b[100005],d[50002],c[50001],x=50000,y,f[50002],step=1;
int a[50001];
main()
{
    int i,j,k,n,l,m,p,q,r,e,g;
    cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }
    queue<int> q1,q2;
    for(j=1;j<=n;j++) if(v[j].size()==1)
   {u.push_back(j); a[j]=1; break;}
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];
            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       r=0;
                       step++;
                       f[q]=step;
                         if(v[i].size()>2)
                       {
                           q1.push(i);
                           f[i]=step;
                           while(!q1.empty()||!q2.empty())
                           {

                               if(r%2==0)
                               {
                                   while(!q1.empty())
                                   {
                                g=q1.front();
                                q1.pop();
                                for(j=0;j<v[g].size();j++)
                                    if(f[v[g][j]]!=step)
                                    {q2.push(v[g][j]);f[v[g][j]]=step; b[x+r]--; }
                                   }
                                   r++;
                               }
                               else
                               {
                                   while(!q2.empty())
                                   {
                                g=q2.front();
                                q2.pop();
                                for(j=0;j<v[g].size();j++)
                                    if(f[v[g][j]]!=step)
                                    {q1.push(v[g][j]);f[v[g][j]]=step; b[x+r]--;  }
                                   }
                                   r++;
                               }
                           }
                       }
                       x++;
                       r=1;
                       step++;
                       f[q]=step;
                       if(v[q].size()>2)
                       {
                           b[x]++;
                           q1.push(i);
                           f[i]=step;
                           while(!q1.empty()||!q2.empty())
                           {

                               if(r%2!=0)
                               {
                                   while(!q1.empty())
                                   {
                                g=q1.front();
                                q1.pop();
                                for(j=0;j<v[g].size();j++)
                                    if(f[v[g][j]]!=step)
                                    {q2.push(v[g][j]);f[v[g][j]]=step; b[x+r]++;  }
                                   }
                                   r++;
                               }
                               else
                               {
                                   while(!q2.empty())
                                   {
                                g=q2.front();
                                q2.pop();
                                for(j=0;j<v[g].size();j++)
                                    if(f[v[g][j]]!=step)
                                    {q1.push(v[g][j]);f[v[g][j]]=step; b[x+r]++; }
                                   }
                                   r++;
                               }
                           }
                       }
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);

                   if(a[p]==0) {x--;
                    b[x]=1;
                    //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                    y+=b[x+k-1];
                    }
                    a[p]=1;
                    c[i]++;
                }
        }
        cout<<y;
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[200005],d[50002],c[50001],x=100002,y,f[50002],step=1;
long long a[50001];
main()
{
    long long i,j,k,n,l,m,p,q,r,e,g,t;
    scanf("%d%d",&n,&k);
    //cin>>n>>k;
    vector<int> v[n+1],u,q1,q2;

    for(i=0; i<n-1; i++)
    {
        //cin>>l>>m;
        scanf("%d%d",&l,&m);
        v[l].push_back(m);
        v[m].push_back(l);
    }
    for(j=1; j<=n; j++) if(v[j].size()==1)
        {
            u.push_back(j);
            a[j]=1;
            break;
        }
    while(!u.empty())
    {
        i=u[u.size()-1];
        p=v[i][c[i]];
        if(c[i]>=v[i].size())
        {
            if(u.size()!=1)
            {
                q=u[u.size()-2];
                r=0;
                step++;
                f[q]=step;
                if(v[i].size()>2)
                {
                    q1.push_back(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2==0)
                        {
                            while(!q1.empty())
                            {
                                g=q1[q1.size()-1];
                                q1.pop_back();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2[q2.size()-1];
                                q2.pop_back();
                                b[x+r]=b[x+r]-v[g].size()+1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
                x++;
                r=1;
                step++;
                f[q]=step;
                if(v[q].size()>2)
                {
                    b[x]++;
                    q1.push_back(i);
                    f[i]=step;
                    while(!q1.empty()||!q2.empty())
                    {

                        if(r%2!=0)
                        {
                            while(!q1.empty())
                            {
                                g=q1[q1.size()-1];
                                q1.pop_back();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q2.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                        else
                        {
                            while(!q2.empty())
                            {
                                g=q2[q2.size()-1];
                                q2.pop_back();
                                b[x+r]=b[x+r]+v[g].size()-1;
                                for(j=0; j<v[g].size(); j++)
                                    if(f[v[g][j]]!=step)
                                    {
                                        q1.push_back(v[g][j]);
                                        f[v[g][j]]=step;
                                    }
                            }
                            r++;
                        }
                    }
                }
            }
            u.pop_back();
        }
        else
        {
            if(a[p]==0) u.push_back(p);
            if(a[p]==0)
            {
                x--;
                b[x]=1;
                //for(j=1;j<=n;j++) d[j]+=b[j+x-1];
                y+=b[x+k-1];
            }
            a[p]=1;
            c[i]++;
        }
    }
    //cout<<y;
    printf("%d\n",y);
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[50000][500],d,c[50000];
int a[500];
main()
{
    int i,j,k,n,l,m,p,q;
    cin>>n>>k;
    vector<int> v[n+1],u;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }

    u.push_back(1); a[1]=1;
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];

            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       b[q][0]=1;
                       b[i][0]=1;

                       for(j=0;j<k;j++)
                       d+=b[q][j]*b[i][k-j-1];

                       for(j=1;j<=k-1;j++)
                       b[q][j]+=b[i][j-1];
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);
                    a[p]=1;
                    c[i]++;
                }
        }

    cout<<d;
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
long long b[50000][500],d,c[50000];
long long a[500];
main()
{
    long long i,j,k,n,l,m,p,q;
    cin>>n>>k;
    vector<long long> v[n+1],u;

    for(i=0;i<n-1;i++)
    {
        cin>>l>>m;
        v[l].push_back(m);
        v[m].push_back(l);
    }

    u.push_back(1); a[1]=1;
    while(!u.empty())
        {
           i=u[u.size()-1];
           p=v[i][c[i]];

            if(c[i]>=v[i].size())
                {
                 if(u.size()!=1)
                    {
                       q=u[u.size()-2];
                       b[q][0]=1;
                       b[i][0]=1;

                       for(j=0;j<k;j++)
                       d+=b[q][j]*b[i][k-j-1];

                       for(j=1;j<=k-1;j++)
                       b[q][j]+=b[i][j-1];
                    }
                    u.pop_back();
                }
            else
                {
                    if(a[p]==0) u.push_back(p);
                    a[p]=1;
                    c[i]++;
                }
        }

    cout<<d;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];
vector<int> sons[MAXN];
ll dp[MAXN][MAXK];
vector<pi> heights;
int max_height = -inf;
void dfs(int node, int father = -1, int height = 0){

    max_height = max(max_height, height);
    heights.pb(mp(height, node));
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        sons[node].pb(v);
        dfs(v, node, height + 1);
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);
    sort(heights.begin(), heights.end());
    ll ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i=n-1; i >= 0; i--){
        int height_actual = heights[i].first;
        int nodo_actual = heights[i].second;
        dp[nodo_actual][0] = 1;

        if(height_actual == max_height)continue;

        for(int j=0; j < sons[nodo_actual].size(); j++){
            int nodo_hijo = sons[nodo_actual][j];

            for(int x=1; x <= k; x++)
                ans += (ll)dp[nodo_hijo][x-1] * dp[nodo_actual][k-x];

            for(int x=0; x < k-1; x++)
                dp[nodo_actual][x+1] += dp[nodo_hijo][x];

        }

    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>

#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

int k;
vector<int> E[50005];
ll DP[50005][505];
ll ans = 0;
bool seen[50005];

void dfs(int node, int father = -1){

    DP[node][0] = 1;
    seen[node] = true;
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        if(seen[v] ) continue;
        dfs(v, node);

        for(int i=1; i <= k; i++)
            ans += DP[node][i - 1] * DP[v][k - i];

        for(int i=0; i < k - 1 ; i++)
            DP[node][i+1] += DP[v][i];
    }
}
int main(){

    int n; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        //E[v].pb(u);

    }

    dfs(0);

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 501;

vector<int> E[MAXN];
vector<int> sons[MAXN];
ll dp[MAXN][MAXK];
vector<pi> heights;
int max_height = -inf;
void dfs(int node, int father = -1, int height = 0){

    max_height = max(max_height, height);
    heights.pb(mp(height, node));
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        sons[node].pb(v);
        dfs(v, node, height + 1);
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);
    sort(heights.begin(), heights.end());
    ll ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i=n-1; i >= 0; i--){
        int height_actual = heights[i].first;
        int nodo_actual = heights[i].second;
        dp[nodo_actual][0] = 1;

        if(height_actual == max_height)continue;

        for(int j=0; j < sons[nodo_actual].size(); j++){
            int nodo_hijo = sons[nodo_actual][j];

            for(int x=1; x <= k; x++)
                ans += (ll)dp[nodo_hijo][x-1] * dp[nodo_actual][k-x];

            for(int x=0; x < k-1; x++)
                dp[nodo_actual][x+1] += dp[nodo_hijo][x];

        }

    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>

#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

int k;
vector<int> E[50005];
ll DP[50005][505];
ll ans = 0;
bool seen[50005];

void dfs(int node, int father = -1){

    DP[node][0] = 1;
    seen[node] = true;
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        if(seen[v] ) continue;
        dfs(v, node);

        for(int i=1; i <= k; i++)
            ans += DP[node][i - 1] * DP[v][k - i];

        for(int i=0; i < k - 1 ; i++)
            DP[node][i+1] += DP[v][i];
    }
}
int main(){

    int n; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);

    }

    dfs(1);

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];

ll dp[MAXN][MAXK];
ll ans = 0;
int k;
bool seen[MAXN];
vector<int> dfs(int node, int father = -1){

    seen[node] = true;

    vector<int> ret(k);
    ret[0] = 1;
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(seen[v]) continue;

        vector<int> aux = dfs(v, node);

        for(int x=1; x <= k; x++)
            ans += aux[x-1] * ret[x-k];

        for(int x=1; x < k; x++)
            ret[x] += aux[x-1];
    }
    return ret;
}
int main(){

    ios_base::sync_with_stdio(false);
    int n; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    memset(dp, 0, sizeof dp);
    memset(seen, false, sizeof seen);

    dfs(1);

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];
vector<int> sons[MAXN];
ll dp[MAXN][MAXK];
vector<pi> heights;
int max_height = -inf;
void dfs(int node, int father = -1, int height = 0){

    max_height = max(max_height, height);
    heights.pb(mp(height, node));
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        sons[node].pb(v);
        dfs(v, node, height + 1);
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);
    sort(heights.begin(), heights.end());
    ll ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i=n-1; i >= 0; i--){
        int height_actual = heights[i].first;
        int nodo_actual = heights[i].second;
        dp[nodo_actual][0] = 1;

        if(height_actual == max_height)continue;

        for(int j=0; j < sons[nodo_actual].size(); j++){
            int nodo_hijo = sons[nodo_actual][j];

            for(int x=1; x <= k; x++){
                ans += (ll)dp[nodo_hijo][x-1] * dp[nodo_actual][k-x];
                if(k == 500)
                    cout << dp[nodo_hijo][x-1] << " " << dp[nodo_actual][k-x] << " " << ans << endl;
            }

            for(int x=0; x < k-1; x++)
                dp[nodo_actual][x+1] += dp[nodo_hijo][x];

        }

    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];
vector<int> sons[MAXN];
ll dp[MAXN][MAXK];
vector<pi> heights;
int max_height = -inf;
void dfs(int node, int father = -1, int height = 0){

    max_height = max(max_height, height);
    heights.pb(mp(height, node));
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        sons[node].pb(v);
        dfs(v, node, height + 1);
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);
    sort(heights.begin(), heights.end());
    ll ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i=n-1; i >= 0; i--){
        int height_actual = heights[i].first;
        int nodo_actual = heights[i].second;
        dp[nodo_actual][0] = 1;

        if(height_actual == max_height)continue;

        for(int j=0; j < sons[nodo_actual].size(); j++){
            int nodo_hijo = sons[nodo_actual][j];

            for(int x=1; x <= k; x++){
                ans += (ll)dp[nodo_hijo][x-1] * dp[nodo_actual][k-x];
                if(k == 500 && dp[nodo_hijo][x-1] && dp[nodo_actual][k-x])
                    cout << dp[nodo_hijo][x-1] << " " << dp[nodo_actual][k-x] << " " << ans << endl;
            }

            for(int x=0; x < k-1; x++)
                dp[nodo_actual][x+1] += dp[nodo_hijo][x];

        }

    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];

ll dp[MAXN][MAXK];
ll ans = 0;
int k;
bool seen[MAXN];
vector<int> dfs(int node, int father = -1){

    vector<int> ret(k+5, 0);
    ret[0] = 1;
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(father == v) continue;

        vector<int> aux = dfs(v, node);

        for(int x=1; x <= k; x++)
            ans += aux[x-1] * ret[x-k];

        for(int x=1; x < k; x++)
            ret[x] += aux[x-1];
    }
    return ret;
}
int main(){

    ios_base::sync_with_stdio(false);
    int n; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    memset(dp, 0, sizeof dp);
    memset(seen, false, sizeof seen);

    dfs(1);

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];
vector<int> sons[MAXN];
ll dp[MAXN][MAXK];
vector<pi> heights;
int max_height = -inf;
void dfs(int node, int father = -1, int height = 0){

    max_height = max(max_height, height);
    heights.pb(mp(height, node));
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        sons[node].pb(v);
        dfs(v, node, height + 1);
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);
    sort(heights.begin(), heights.end());
    ll ans = 0;
    for(int i=n-1; i >= 0; i--){
        int height_actual = heights[i].first;
        int nodo_actual = heights[i].second;
        dp[nodo_actual][0] = 1;

        if(height_actual == max_height)continue;

        for(int j=0; j < sons[nodo_actual].size(); j++){
            int nodo_hijo = sons[nodo_actual][j];

            for(int x=1; x <= k; x++)
                ans += dp[nodo_hijo][x-1] * dp[nodo_actual][k-x];

            for(int x=0; x < k-1; x++)
                dp[nodo_actual][x+1] += dp[nodo_hijo][x];

        }

    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];
vector<int> sons[MAXN];
ll dp[MAXN][MAXK];
vector<pi> heights;
int max_height = -inf;
void dfs(int node, int father = -1, int height = 0){

    max_height = max(max_height, height);
    heights.pb(mp(height, node));
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        sons[node].pb(v);
        dfs(v, node, height + 1);
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);
    sort(heights.begin(), heights.end());
    ll ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i=n-1; i >= 0; i--){
        int height_actual = heights[i].first;
        int nodo_actual = heights[i].second;
        dp[nodo_actual][0] = 1;

        if(height_actual == max_height)continue;

        for(int j=0; j < sons[nodo_actual].size(); j++){
            int nodo_hijo = sons[nodo_actual][j];

            for(int x=1; x <= k; x++){
                ans += (ll)dp[nodo_hijo][x-1] * dp[nodo_actual][k-x];

            }

            for(int x=1; x <= k-1; x++)
                dp[nodo_actual][x] += dp[nodo_hijo][x-1];

        }

    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>

#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

int k;
vector<int> E[50005];
ll DP[50005][505];
ll ans = 0;
bool seen[50005];

void dfs(int node, int father = -1){

    DP[node][0] = 1;
    seen[node] = true;
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        if(seen[v] ) continue;
        dfs(v, node);

        for(int i=1; i <= k; i++)
            ans += DP[node][i - 1] * DP[v][k - i];

        for(int i=0; i < k - 1 ; i++)
            DP[node][i+1] += DP[v][i];
    }
}
int main(){

    int n; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        //E[v].pb(u);

    }

    dfs(1);

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];

ll dp[MAXN][MAXK];
ll ans = 0;
int k;

void dfs(int node, int father = -1){

    dp[node][0]  = 1;

    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;

        dfs(v, node);

        for(int x=1; x <= k; x++)
            ans += dp[v][x-1] * dp[node][k-x];

        for(int x=1; x < k; x++)
            dp[node][x] += dp[v][x-1];
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    memset(dp, 0, sizeof dp);
    dfs(1);

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];

ll ans = 0;
int k;

vector<int> dfs(int node, int father = -1){

    vector<int> ret(k+5, 0);
    ret[0] = 1;
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(father == v) continue;

        vector<int> aux = dfs(v, node);

        for(int x=1; x <= k; x++)
            ans += aux[x-1] * ret[k-x];

        for(int x=1; x < k; x++)
            ret[x] += aux[x-1];
    }
    return ret;
}
int main(){

    ios_base::sync_with_stdio(false);
    int n; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

#define inf (1 << 30)
#define INF (1<<45LL)
#define pb push_back
#define mp make_pair
using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

/*
 *
 *      PUCMM PROGRAMMING FORCE
 *
 * */

const int MAXN = 50001;
const int MAXK  = 51;

vector<int> E[MAXN];
vector<int> sons[MAXN];
ll dp[MAXN][MAXK];
vector<pi> heights;
int max_height = -inf;
void dfs(int node, int father = -1, int height = 0){

    max_height = max(max_height, height);
    heights.pb(mp(height, node));
    for(int i=0; i < E[node].size(); i++){
        int v = E[node][i];
        if(v == father) continue;
        sons[node].pb(v);
        dfs(v, node, height + 1);
    }
}
int main(){

    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;

    for(int i=1; i < n; i++){
        int u, v; cin >> u >> v;
        E[u].pb(v);
        E[v].pb(u);
    }

    dfs(1);
    sort(heights.begin(), heights.end());
    ll ans = 0;
    for(int i=n-1; i >= 0; i--){
        int height_actual = heights[i].first;
        int nodo_actual = heights[i].second;

        if(height_actual == max_height){

            for(int i=1; i <= k; i++) dp[nodo_actual][i] = 0;

            continue;
        }
        dp[nodo_actual][0] = 1;
        for(int x=1; x <= k; x++){

            ll cur = 0;
            for(int j=0; j < sons[nodo_actual].size(); j++){
                int nodo_hijo = sons[nodo_actual][j];
            //  cout << nodo_hijo << " " << nodo_actual << " " << x << endl;
                ans += dp[nodo_hijo][x-1] * dp[nodo_actual][k-x+1];
                dp[nodo_actual][x] += dp[nodo_hijo][x-1];
            //  cout << "( " << nodo_actual << " , " << x << ") = " << dp[nodo_actual][x] << endl;
            }
        }
    }

    for(int i=1; i <= n; i++) ans += dp[i][k];
    cout << ans << endl;
    return 0;
}


#include <iostream>

using namespace std;

int dp[50001][501]; // checking if MLE

int main(){

    int n, k; cin >> n >> k;
    return 0;
}