#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];
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(seen[v]) 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);
    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];

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

    dp[node][0]  = 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] * dp[node][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);
    }

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

    dfs(1);

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


/*
Template belongs to : Himanshu Jaju [himanshujaju]
*/

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

typedef long long int LL;

#define inp_s     ios_base::sync_with_stdio(false)
#define DRT()     int test_case;cin>>test_case;while(test_case--)

#define VI        vector<int>
#define VS        vector<string>
#define VLL       vector<LL>
#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     c.size()
#define clr(c)    c.clear()
#define msi       map<string,int>
#define msit      map<string,int>::iterator
#define pb        push_back
#define mp        make_pair

#define GI(x)     scanf("%d",&x)

#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define RFOR(i,a,b)     for(int i=b-1;i>=a;i--)

#define gcd(a,b)  __gcd(a,b)
#define MOD       1000000007
#define EPS       1E-10

#define PI  acos(-1)

#define CASE(x)   cout << "Case #" << x << ": ";

int dp[500001][501];

vector<VI> graph;
vector<int> parent;

int counter(int v , int d)
{
    if(!d) return 1;
    else if(dp[v][d] != -1) return dp[v][d];
    int ret = 0;
    FOR(i,0,sz(graph[v]))
    {
        int u = graph[v][i];
        if(u == parent[v]) continue;
        parent[u] = v;
        ret += counter(u , d - 1);
    }
    return (dp[v][d] = ret);
}

int main()
{
    FOR(i,0,500001) FOR(j,0,501) dp[i][j] = -1;
    int n,k;
    cin >> n >> k;
    parent.resize(n,-1);
    graph.resize(n);
    FOR(i,1,n)
    {
        int a,b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    LL ans = 0;
    FOR(i,0,n) FOR(j,0,k+1) dp[i][j] = counter(i,j);
    LL temp = 0;
    FOR(i,0,n)
    {
        FOR(j,1,k)
        {
            FOR(l,0,sz(graph[i]))
            {
                if(graph[i][l] == parent[i]) continue;
                int node = graph[i][l];
                temp += (counter(node , j - 1) * (counter(i , k - j) - counter(node , k - j - 1)));
            }
        }
        ans += counter(i , k);
    }
    ans += (temp / 2);
    cout << ans << endl;
    return 0;
}


/*
Template belongs to : Himanshu Jaju [himanshujaju]
*/

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

typedef long long int LL;

#define inp_s     ios_base::sync_with_stdio(false)
#define DRT()     int test_case;cin>>test_case;while(test_case--)

#define VI        vector<int>
#define VS        vector<string>
#define VLL       vector<LL>
#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     c.size()
#define clr(c)    c.clear()
#define msi       map<string,int>
#define msit      map<string,int>::iterator
#define pb        push_back
#define mp        make_pair

#define GI(x)     scanf("%d",&x)

#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define RFOR(i,a,b)     for(int i=b-1;i>=a;i--)

#define gcd(a,b)  __gcd(a,b)
#define MOD       1000000007
#define EPS       1E-10

#define PI  acos(-1)

#define CASE(x)   cout << "Case #" << x << ": ";

LL dp[50001][501];

vector<VI> graph;
vector<int> parent;

int counter(int v , int d)
{
    if(!d) return 1;
    else if(dp[v][d] != -1) return dp[v][d];
    int ret = 0;
    FOR(i,0,sz(graph[v]))
    {
        int u = graph[v][i];
        if(u == parent[v]) continue;
        parent[u] = v;
        ret += counter(u , d - 1);
    }
    return (dp[v][d] = ret);
}

int main()
{
    FOR(i,0,50001) FOR(j,0,501) dp[i][j] = -1;
    int n,k;
    GI(n);
    GI(k);
    parent.resize(n,-1);
    graph.resize(n);
    FOR(i,1,n)
    {
        int a,b;
        GI(a);
        GI(b);
        a -= 1;
        b -= 1;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    LL ans = 0;
    LL temp = 0;
    FOR(i,0,n)
    {
        FOR(l,0,sz(graph[i]))
        {
            if(graph[i][l] == parent[i]) continue;
            FOR(j,1,k)
            {
                int node = graph[i][l];
                temp += (counter(node , j - 1) * (counter(i , k - j) - counter(node , k - j - 1)));
            }
        }
        ans += counter(i , k);
    }
    temp /= 2;
    ans += temp;
    printf("%I64d" , ans);
    return 0;
}


/*
Template belongs to : Himanshu Jaju [himanshujaju]
*/

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

typedef long long int LL;

#define inp_s     ios_base::sync_with_stdio(false)
#define DRT()     int test_case;cin>>test_case;while(test_case--)

#define VI        vector<int>
#define VS        vector<string>
#define VLL       vector<LL>
#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     c.size()
#define clr(c)    c.clear()
#define msi       map<string,int>
#define msit      map<string,int>::iterator
#define pb        push_back
#define mp        make_pair

#define GI(x)     scanf("%d",&x)

#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define RFOR(i,a,b)     for(int i=b-1;i>=a;i--)

#define gcd(a,b)  __gcd(a,b)
#define MOD       1000000007
#define EPS       1E-10

#define PI  acos(-1)

#define CASE(x)   cout << "Case #" << x << ": ";

LL dp[50001][501];

vector<VI> graph;
vector<int> parent;

int counter(int v , int d)
{
    if(!d) return 1;
    else if(dp[v][d] != -1) return dp[v][d];
    int ret = 0;
    FOR(i,0,sz(graph[v]))
    {
        int u = graph[v][i];
        if(u == parent[v]) continue;
        parent[u] = v;
        ret += counter(u , d - 1);
    }
    return (dp[v][d] = ret);
}

int main()
{
    FOR(i,0,50001) FOR(j,0,501) dp[i][j] = -1;
    int n,k;
    cin >> n >> k;
    parent.resize(n,-1);
    graph.resize(n);
    FOR(i,1,n)
    {
        int a,b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    LL ans = 0;
    FOR(i,0,n)
    {
        FOR(j,1,k)
        {
            FOR(l,0,sz(graph[i]))
            {
                if(graph[i][l] == parent[i]) continue;
                int node = graph[i][l];
                ans += (counter(node , j - 1) * (counter(i , k - j) - counter(node , k - j - 1)));
            }
        }
        ans += counter(i , k);
    }
    cout << ans << endl;
    return 0;
}


/*
Template belongs to : Himanshu Jaju [himanshujaju]
*/

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

typedef long long int LL;

#define inp_s     ios_base::sync_with_stdio(false)
#define DRT()     int test_case;cin>>test_case;while(test_case--)

#define VI        vector<int>
#define VS        vector<string>
#define VLL       vector<LL>
#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     c.size()
#define clr(c)    c.clear()
#define msi       map<string,int>
#define msit      map<string,int>::iterator
#define pb        push_back
#define mp        make_pair

#define GI(x)     scanf("%d",&x)

#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define RFOR(i,a,b)     for(int i=b-1;i>=a;i--)

#define gcd(a,b)  __gcd(a,b)
#define MOD       1000000007
#define EPS       1E-10

#define PI  acos(-1)

#define CASE(x)   cout << "Case #" << x << ": ";

LL dp[50001][501];
vector<VI> graph;
int n,k;
LL ans = 0 , temp = 0;

void dfs(int u , int par)
{
    FOR(i,0,sz(graph[u]))
    {
        int v = graph[u][i];
        if(v != par) dfs(v , u);
    }
    dp[u][0] = 1;
    FOR(i,0,sz(graph[u]))
    {
        int v = graph[u][i];
        if(v == par) continue;
        FOR(j,0,k) dp[u][j + 1] += dp[v][j];
    }
    ans += dp[u][k];
    FOR(i,0,sz(graph[u]))
    {
        int v = graph[u][i];
        if(v == par) continue;
        FOR(j,1,k)
        {
            temp += dp[v][j-1] * (dp[u][k - j] - dp[v][k - j - 1]);
        }
    }
}

int main()
{
    FOR(i,0,50001) FOR(j,0,501) dp[i][j] = 0;
    GI(n);
    GI(k);
    graph.resize(n);
    FOR(i,1,n)
    {
        int a,b;
        GI(a);
        GI(b);
        a -= 1;
        b -= 1;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    dfs(0 , 0);
    temp /= 2;
    ans += temp;
    cout << ans << endl;
    return 0;
}


/*
Template belongs to : Himanshu Jaju [himanshujaju]
*/

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

typedef long long int LL;

#define inp_s     ios_base::sync_with_stdio(false)
#define DRT()     int test_case;cin>>test_case;while(test_case--)

#define VI        vector<int>
#define VS        vector<string>
#define VLL       vector<LL>
#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     c.size()
#define clr(c)    c.clear()
#define msi       map<string,int>
#define msit      map<string,int>::iterator
#define pb        push_back
#define mp        make_pair

#define GI(x)     scanf("%d",&x)

#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define RFOR(i,a,b)     for(int i=b-1;i>=a;i--)

#define gcd(a,b)  __gcd(a,b)
#define MOD       1000000007
#define EPS       1E-10

#define PI  acos(-1)

#define CASE(x)   cout << "Case #" << x << ": ";

LL dp[50001][501];

vector<VI> graph;
vector<int> parent;

int counter(int v , int d)
{
    if(!d) return 1;
    else if(dp[v][d] != -1) return dp[v][d];
    int ret = 0;
    FOR(i,0,sz(graph[v]))
    {
        int u = graph[v][i];
        if(u == parent[v]) continue;
        parent[u] = v;
        ret += counter(u , d - 1);
    }
    return (dp[v][d] = ret);
}

int main()
{
    FOR(i,0,50001) FOR(j,0,501) dp[i][j] = -1;
    int n,k;
    cin >> n >> k;
    parent.resize(n,-1);
    graph.resize(n);
    FOR(i,1,n)
    {
        int a,b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    LL ans = 0;
    LL temp = 0;
    FOR(i,0,n)
    {
        FOR(l,0,sz(graph[i]))
        {
            if(graph[i][l] == parent[i]) continue;
            FOR(j,1,k)
            {
                int node = graph[i][l];
                temp += (counter(node , j - 1) * (counter(i , k - j) - counter(node , k - j - 1)));
            }
        }
        ans += counter(i , k);
    }
    temp /= 2;
    ans += temp;
    cout << ans << endl;
    return 0;
}


/*
Template belongs to : Himanshu Jaju [himanshujaju]
*/

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

typedef long long int LL;

#define inp_s     ios_base::sync_with_stdio(false)
#define DRT()     int test_case;cin>>test_case;while(test_case--)

#define VI        vector<int>
#define VS        vector<string>
#define VLL       vector<LL>
#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     c.size()
#define clr(c)    c.clear()
#define msi       map<string,int>
#define msit      map<string,int>::iterator
#define pb        push_back
#define mp        make_pair

#define GI(x)     scanf("%d",&x)

#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define RFOR(i,a,b)     for(int i=b-1;i>=a;i--)

#define gcd(a,b)  __gcd(a,b)
#define MOD       1000000007
#define EPS       1E-10

#define PI  acos(-1)

#define CASE(x)   cout << "Case #" << x << ": ";

LL dp[500001][501];

vector<VI> graph;
vector<int> parent;

int counter(int v , int d)
{
    if(!d) return 1;
    else if(dp[v][d] != -1) return dp[v][d];
    int ret = 0;
    FOR(i,0,sz(graph[v]))
    {
        int u = graph[v][i];
        if(u == parent[v]) continue;
        parent[u] = v;
        ret += counter(u , d - 1);
    }
    return (dp[v][d] = ret);
}

int main()
{
    FOR(i,0,500001) FOR(j,0,501) dp[i][j] = -1;
    int n,k;
    cin >> n >> k;
    parent.resize(n,-1);
    graph.resize(n);
    FOR(i,1,n)
    {
        int a,b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    LL ans = 0;
    FOR(i,0,n) FOR(j,0,k+1) dp[i][j] = counter(i,j);
    LL temp = 0;
    FOR(i,0,n)
    {
        FOR(j,1,k)
        {
            FOR(l,0,sz(graph[i]))
            {
                if(graph[i][l] == parent[i]) continue;
                int node = graph[i][l];
                temp += (counter(node , j - 1) * (counter(i , k - j) - counter(node , k - j - 1)));
            }
        }
        ans += counter(i , k);
    }
    ans += (temp / 2);
    cout << ans << endl;
    return 0;
}


/*
Template belongs to : Himanshu Jaju [himanshujaju]
*/

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

typedef long long int LL;

#define inp_s     ios_base::sync_with_stdio(false)
#define DRT()     int test_case;cin>>test_case;while(test_case--)

#define VI        vector<int>
#define VS        vector<string>
#define VLL       vector<LL>
#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     c.size()
#define clr(c)    c.clear()
#define msi       map<string,int>
#define msit      map<string,int>::iterator
#define pb        push_back
#define mp        make_pair

#define GI(x)     scanf("%d",&x)

#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define RFOR(i,a,b)     for(int i=b-1;i>=a;i--)

#define gcd(a,b)  __gcd(a,b)
#define MOD       1000000007
#define EPS       1E-10

#define PI  acos(-1)

#define CASE(x)   cout << "Case #" << x << ": ";

int dp[50001][501];

vector<VI> graph;
vector<int> parent;

int counter(int v , int d)
{
    if(!d) return 1;
    else if(dp[v][d] != -1) return dp[v][d];
    int ret = 0;
    FOR(i,0,sz(graph[v]))
    {
        int u = graph[v][i];
        if(u == parent[v]) continue;
        parent[u] = v;
        ret += counter(u , d - 1);
    }
    return (dp[v][d] = ret);
}

int main()
{
    FOR(i,0,50001) FOR(j,0,501) dp[i][j] = -1;
    int n,k;
    cin >> n >> k;
    parent.resize(n,-1);
    graph.resize(n);
    FOR(i,1,n)
    {
        int a,b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    LL ans = 0;
    FOR(i,0,n) FOR(j,0,k+1) dp[i][j] = counter(i,j);
    LL temp = 0;
    FOR(i,0,n)
    {
        FOR(j,1,k)
        {
            FOR(l,0,sz(graph[i]))
            {
                if(graph[i][l] == parent[i]) continue;
                int node = graph[i][l];
                temp += (counter(node , j - 1) * (counter(i , k - j) - counter(node , k - j - 1)));
            }
        }
        ans += counter(i , k);
    }
    ans += (temp / 2);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501]={0};
vector<int> v[1000001];
map<long,long> parent;
map<long,long>visit;
long ans=0;
long k;
void dfs(long src)
    {
            visit[src]=1;
            vl[src][0]=1;
            for(long i=0;i<v[src].size();i++)
                {
                    if(!visit[v[src][i]])
                    {

                        vl[src][1]++;
                        parent[v[src][i]]=src;
                        dfs(v[src][i]);
                        for(long j=2;j<=k;j++)
                        vl[src][j]+=vl[v[src][i]][j-1];

                }
                    }

            //cout<<src<<" "<<vl[src][k]<<endl;

    }

long solve(long n)
    {
        long b;
   long prev;
        for(long i=1;i<=n;i++)
            {
                b=k-1;
               //cout<<"add "<<vl[i][k]<<" ";
                ans=ans+vl[i][k];
                long c=i;
                while( (b-1)>=0)
                    {
                        if(parent[c]==-1)
                            break;
                        prev=c;
                        c=parent[c];

                            //cout<<"ans"<<i<<" "<<vl[c][b]<<" "<<vl[prev][b-1]<<" ";

                            ans=ans+vl[c][b]-vl[prev][b-1];

                            b--;
                    }
                    if(b==0 && parent[c]!=-1)
                        ans++;

            }

        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long n,m,a,b;
    cin>>n>>m;
    k=m;
    //cout<<n<<m<<endl;
    for(long i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    dfs(1);
    parent[1]=-1;
   /* for(long i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501];
vector<int> v[1000001];
map<long,long> parent;
map<long,long>visit;
long ans=0;
void dfs(long src, long par ,long ppar,long l)
    {
           if(ppar==1)
            parent[src]=par;
           // cout<<src<<" ";
        if(!visit[src])
            vl[ppar][l]+=1;
           for(long i=0;i<v[src].size();i++)
               {
                       if(v[src][i]!=par && !visit[v[src][i]])
                           {

                                dfs(v[src][i],src,ppar,l+1);
                            }
               }
    }

long solve(long n,long k)
    {
        long b;
        for(long i=1;i<=n;i++)
            {
                b=k-1;
               // cout<<"add "<<vl[i][k]<<" ";
                ans=ans+vl[i][k];
                long c=i;
                while( b>=0)
                    {
                        if(c==parent[c])
                            break;
                        c=parent[c];

                            //cout<<"ans"<<i<<" "<<vl[c][b]<<" "<<vl[i][b-1]<<" ";
                            ans=ans+vl[c][b]-vl[i][b-1];

                    b--;
                    }
            }
        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long n,m,a,b;
    cin>>n>>m;
    //cout<<n<<m<<endl;
    for(long i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    for(long i=1;i<=n;i++)
    {

        dfs(i,i,i,0);
       /* for(long j=0;j<=m;j++)
        {
            cout<<vl[i][j]<<" ";
        }*/
        visit[i]=1;
       // cout<<endl;
    }
    /*for(long i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n,m)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501];
vector<int> v[1000001];
map<long,long> parent;
map<long,long>visit;
long ans=0;
void dfs(long src, long par ,long ppar,long l)
    {
           if(ppar==1)
            parent[src]=par;
           // cout<<src<<" ";
        if(!visit[src])
            vl[ppar][l]+=1;
           for(long i=0;i<v[src].size();i++)
               {
                       if(v[src][i]!=par && !visit[v[src][i]])
                           {

                                dfs(v[src][i],src,ppar,l+1);
                            }
               }
    }

long solve(long n,long k)
    {
        long b;
   long prev;
        for(long i=1;i<=n;i++)
            {
                b=k-1;
               // cout<<"add "<<vl[i][k]<<" ";
                ans=ans+vl[i][k];
                long c=i;
                while( (b-1)>=0)
                    {
                        if(parent[c]==-1)
                            break;
                        prev=c;
                        c=parent[c];

                            //cout<<"ans"<<i<<" "<<vl[c][b]<<" "<<vl[i][b-1]<<" ";

                       if(b-1>=0)
                        ans=ans+vl[c][b]-vl[prev][b-1];

                    b--;
                    }
                if(b==0 && parent[c]!=-1)
                    {
                        ans++;
                    }
            }

        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long n,m,a,b;
    cin>>n>>m;
    //cout<<n<<m<<endl;
    for(long i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    for(long i=1;i<=n;i++)
    {

        dfs(i,i,i,0);
       /* for(long j=0;j<=m;j++)
        {
            cout<<vl[i][j]<<" ";
        }*/
        visit[i]=1;
        parent[1]=-1;
       // cout<<endl;
    }
    /*for(long i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n,m)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501];
vector<int> v[1000001];
map<long,long> parent;
map<long,long>visit;
long long ans=0;
void dfs(long src, long par ,long ppar,long l)
    {
           if(ppar==1)
            parent[src]=par;
           // cout<<src<<" ";
        if(!visit[src])
            vl[ppar][l]+=1;
           for(long i=0;i<v[src].size();i++)
               {
                       if(v[src][i]!=par && !visit[v[src][i]])
                           {

                                dfs(v[src][i],src,ppar,l+1);
                            }
               }
    }

long solve(long n,long k)
    {
        long b;
        for(long i=1;i<=n;i++)
            {
                b=k-1;
               // cout<<"add "<<vl[i][k]<<" ";
                ans=ans+vl[i][k];
                long c=i;
                while( b>=0)
                    {
                        if(c==parent[c])
                            break;
                        c=parent[c];

                            //cout<<"ans"<<i<<" "<<vl[c][b]<<" "<<vl[i][b-1]<<" ";
                            ans=ans+vl[c][b]-vl[i][b-1];

                    b--;
                    }
            }
        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long n,m,a,b;
    cin>>n>>m;
    //cout<<n<<m<<endl;
    for(long i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    for(long i=1;i<=n;i++)
    {

        dfs(i,i,i,0);
       /* for(long j=0;j<=m;j++)
        {
            cout<<vl[i][j]<<" ";
        }*/
        visit[i]=1;
       // cout<<endl;
    }
    /*for(long i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n,m)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501]={0};
vector<int> v[1000001];
vector<int> parent[50001];
map<long long int,long long int>visit;
long long int ans=0;
long long int k;
void dfs(long long int src)
    {
            visit[src]=1;
            vl[src][0]=1;
            for(long long int i=0;i<v[src].size();i++)
                {
                    if(!visit[v[src][i]])
                    {

                        vl[src][1]++;
                        parent[v[src][i]].push_back(src);
                        dfs(v[src][i]);
                        for(long long int j=2;j<=k;j++)
                        vl[src][j]+=vl[v[src][i]][j-1];

                }
                    }

            //cout<<src<<" "<<vl[src][k]<<endl;

    }

long long int solve(long long int n)
    {
        //cout<<"hi";
        long long int b;
        long long int prev;
        for(long long int i=1;i<=n;i++)
            {

                ans=ans+vl[i][k];
                long long int c=i;
                long long int j=1;
                while(parent[c].size() && (k-j-1)>=0)
                {
                    int par=parent[c][0];
                    ans=ans+vl[par][k-j]-vl[c][k-j-1];
                    c=par;
                    j++;
                }if((k-j)==0 && parent[c].size())
                        ans++;

            }

        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long long int n,m,a,b;
    cin>>n>>m;
    k=m;
    //cout<<n<<m<<endl;
    for(long long int i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    dfs(1);
    //cout<<"hello"<<endl;
   /* for(long long int i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501];
vector<int> v[1000001];
map<long,long> parent;
map<long,long>visit;
long long ans=0;
void dfs(long src, long par ,long ppar,long l)
    {
           if(ppar==1)
            parent[src]=par;
           // cout<<src<<" ";
        if(!visit[src])
            vl[ppar][l]+=1;
           for(long i=0;i<v[src].size();i++)
               {
                       if(v[src][i]!=par && !visit[v[src][i]])
                           {

                                dfs(v[src][i],src,ppar,l+1);
                            }
               }
    }

long solve(long n,long k)
    {
        long b;
        for(long i=1;i<=n;i++)
            {
                b=k-1;
               // cout<<"add "<<vl[i][k]<<" ";
                ans=ans+vl[i][k];
                long c=i;
                while( b>=0)
                    {

                          c=parent[c];

                            //cout<<"ans"<<i<<" "<<vl[c][b]<<" "<<vl[i][b-1]<<" ";
                            ans=ans+vl[c][b]-vl[i][b-1];

                             b--;
                    }
            }
        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long n,m,a,b;
    cin>>n>>m;
    //cout<<n<<m<<endl;
    for(long i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    for(long i=1;i<=n;i++)
    {

        dfs(i,i,i,0);
       /* for(long j=0;j<=m;j++)
        {
            cout<<vl[i][j]<<" ";
        }*/
        visit[i]=1;
       // cout<<endl;
    }
    /*for(long i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n,m)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501]={0};
vector<int> v[1000001];
vector<int> parent[50001];
map<long,long>visit;
long ans=0;
long k;
void dfs(long src)
    {
            visit[src]=1;
            vl[src][0]=1;
            for(long i=0;i<v[src].size();i++)
                {
                    if(!visit[v[src][i]])
                    {

                        vl[src][1]++;
                        parent[v[src][i]].push_back(src);
                        dfs(v[src][i]);
                        for(long j=2;j<=k;j++)
                        vl[src][j]+=vl[v[src][i]][j-1];

                }
                    }

            //cout<<src<<" "<<vl[src][k]<<endl;

    }

long solve(long n)
    {
        //cout<<"hi";
        long b;
        long prev;
        for(long i=1;i<=n;i++)
            {

                ans=ans+vl[i][k];
                long c=i;
                long j=1;
                while(parent[c].size() && (k-j-1)>=0)
                {
                    int par=parent[c][0];
                    ans=ans+vl[par][k-j]-vl[c][k-j-1];
                    c=par;
                    j++;
                }if((k-j)==0 && parent[c].size())
                        ans++;

            }

        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long n,m,a,b;
    cin>>n>>m;
    k=m;
    //cout<<n<<m<<endl;
    for(long i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    dfs(1);
    //cout<<"hello"<<endl;
   /* for(long i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n)/2<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int vl[50001][501];
vector<int> v[1000001];
map<long,long> parent;
map<long,long>visit;
long ans=0;
void dfs(long src, long par ,long ppar,long l)
    {
           if(ppar==1)
            parent[src]=par;
           // cout<<src<<" ";
        if(!visit[src])
            vl[ppar][l]+=1;
           for(long i=0;i<v[src].size();i++)
               {
                       if(v[src][i]!=par && !visit[v[src][i]])
                           {

                                dfs(v[src][i],src,ppar,l+1);
                            }
               }
    }

long solve(long n,long k)
    {
        long b;
        for(long i=1;i<=n;i++)
            {
                b=k-1;
               // cout<<"add "<<vl[i][k]<<" ";
                ans=ans+vl[i][k];
                long c=i;
                while( b>=0)
                    {
                        if(parent[c]==-1)
                            break;
                        c=parent[c];

                            //cout<<"ans"<<i<<" "<<vl[c][b]<<" "<<vl[i][b-1]<<" ";

                        ans=ans+vl[c][b]-vl[i][b-1];

                    b--;
                    }
            }

        return ans;
    }

int main()
{
    //cout<<"land"<<endl;
   long n,m,a,b;
    cin>>n>>m;
    //cout<<n<<m<<endl;
    for(long i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }

    for(long i=1;i<=n;i++)
    {

        dfs(i,i,i,0);
       /* for(long j=0;j<=m;j++)
        {
            cout<<vl[i][j]<<" ";
        }*/
        visit[i]=1;
        parent[1]=-1;
       // cout<<endl;
    }
    /*for(long i=1;i<=n;i++)
        cout<<parent[i]<<" ";
    cout<<endl;*/
    cout<<solve(n,m)/2<<endl;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

int dp[50009][509];
int n,K;
vector<vector<int> > g;
int DP(int x, int len)
{
	if (dp[x][len] != -1)
		return dp[x][len];
	int res = 0;
	FOR(i,g[x].size())
	{
		int to = g[x][i];
		if(len > 0)
			res += DP(to,len-1);
	}
	if (len == 0)
		res++;
	return dp[x][len] = res;
}
void clean_dfs(int x, int pr)
{
	FOR(i,g[x].size())
	{
		if (g[x][i] == pr)
		{
			swap(g[x][i],g[x].back());
			g[x].pop_back();
			i--;
			continue;
		}
		clean_dfs(g[x][i],x);
	}
}

LL calc(int x)
{
	LL res = 0;
	FOR(i,g[x].size())
		res+=calc(g[x][i]);
	LL tres = 0;
	for (int i=1;i<K;i++)
	{
		FOR(j,g[x].size())
		{
			tres += (LL)DP(g[x][j],i-1) * (DP(x,K-i) - DP(g[x][j],K-i-1));
		}
	}
	tres/=2;
	res += tres;
	res += DP(x,K);
	return res;
}
int main()
{
	CL(dp,-1);
	freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&K);
	g.resize(n);
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	clean_dfs(0,-1);
	cout << calc(0) << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

int dp[50009][509];
int n,K;
vector<vector<int> > g;
int DP(int x, int len)
{
	if (dp[x][len] != -1)
		return dp[x][len];
	int res = 0;
	if (len > 0 && DP(x,len-1) > 0)
	{
		FOR(i,g[x].size())
		{
			if(len > 0)
				res += DP(g[x][i],len-1);
		}
	}
	if (len == 0)
		res++;
	return dp[x][len] = res;
}
void clean_dfs(int x, int pr)
{
	FOR(i,g[x].size())
	{
		if (g[x][i] == pr)
		{
			swap(g[x][i],g[x].back());
			g[x].pop_back();
			i--;
			continue;
		}
		clean_dfs(g[x][i],x);
	}
}

LL calc(int x)
{
	LL res = 0;
	FOR(i,g[x].size())
		res+=calc(g[x][i]);
	LL tres = 0;
	for (int i=1;i<K;i++)
	{
		FOR(j,g[x].size())
		{
			tres += (LL)DP(g[x][j],i-1) * (DP(x,K-i) - DP(g[x][j],K-i-1));
		}
	}
	tres/=2;
	res += tres;
	res += DP(x,K);
	return res;
}
int main()
{
	CL(dp,-1);
	//freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&K);
	g.resize(n);
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	clean_dfs(0,-1);
	cout << calc(0) << endl;
	return 0;
}


//#pragma comment(linker,"/STACK
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

struct st
{
	int ar[502];
	st()
	{
		CL(ar,0);
	}
	st inc()
	{
		st res;
		FOR(i,502-1)
		{
			res.ar[i+1] = ar[i];
		}
		return res;
	}
	friend st operator + (const st &a, const st &b)
	{
		st res;
		FOR(i,502)
		{
			res.ar[i] += a.ar[i] + b.ar[i];
		}
		return res;
	}
	friend st operator - (const st &a, const st &b)
	{
		st res;
		FOR(i,502)
		{
			res.ar[i] += a.ar[i] - b.ar[i];
		}
		return res;
	}
};
int n;
st dp[150009];
char b[150009];
st v[50009];
int last[50009];
char ty[50009];
st def_res;
vector<vector<int> > g;
map<pair<int,int> ,int> mp;
int ID(pair<int,int> x)
{
	if (mp.find(x) == mp.end())
		mp[x] = mp.size();
	return mp[x] - 1;
}
st DP(int x, int pr)
{
	int t = ID(MP(pr,x));
	if (g[x].size() == 1 && pr != -1)
	{
		b[t] = 1;
		return dp[t]=def_res;
	}
	if (b[t] == 1)
		return dp[t];
	else if (ty[x] == 1)
	{
		if (last[x] != -1)
		{
			v[x] = v[x] + DP(last[x], x);
		}
		if (pr != -1)
		{
			v[x] = v[x] - DP(pr,x);//dp[ID(MP(x,pr))];
		}
		last[x] = pr;
		return dp[t] = v[x].inc();
	}
	st res;
	for (int i=0;i < g[x].size();i++)
	{
		if (g[x][i] == pr)
			continue;
		res = res + DP(g[x][i],x);
	}
	res.ar[0]++;
	b[t] = 1;
	ty[x] = 1;
	last[x] = pr;
	v[x] = res;
	return dp[t] = res.inc();
}
int K;
int main()
{
	freopen("input.txt","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d%d",&n,&K);
	g.resize(n);
	def_res.ar[1]=1;
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	LL res = 0;
	int CC = 0;
	FOR(i,n)
	{
		if (i == 49008)
			CC = CC;
		res += CC =  DP(i,-1).ar[K+1];
		if (CC == 0)
			CC = CC;
	}
	cout << res/2 << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

int dp[50009][509];
int n,K;
vector<vector<int> > g;
int DP(int x, int len)
{
	if (dp[x][len] != -1)
		return dp[x][len];
	int res = 0;
	FOR(i,g[x].size())
	{
		int to = g[x][i];
		if(len > 0)
			res += DP(to,len-1);
	}
	if (len == 0)
		res++;
	return dp[x][len] = res;
}
void clean_dfs(int x, int pr)
{
	FOR(i,g[x].size())
	{
		if (g[x][i] == pr)
		{
			swap(g[x][i],g[x].back());
			g[x].pop_back();
			i--;
			continue;
		}
		clean_dfs(g[x][i],x);
	}
}

LL calc(int x)
{
	LL res = 0;
	FOR(i,g[x].size())
		res+=calc(g[x][i]);
	LL tres = 0;
	for (int i=1;i<K;i++)
	{
		FOR(j,g[x].size())
		{
			tres += (LL)DP(g[x][j],i-1) * (DP(x,K-i) - DP(g[x][j],K-i-1));
		}
	}
	tres/=2;
	res += tres;
	res += DP(x,K);
	return res;
}
int main()
{
	CL(dp,-1);
	//freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&K);
	g.resize(n);
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	clean_dfs(0,-1);
	cout << calc(0) << endl;
	return 0;
}


//#pragma comment(linker,"/STACK
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

struct st
{
	static const int N = 502;
	int ar[N];
	st()
	{
		CL(ar,0);
	}
	st inc()
	{
		st res;
		FOR(i,N-1)
		{
			res.ar[i+1] = ar[i];
		}
		return res;
	}
	friend st operator + (const st &a, const st &b)
	{
		st res;
		FOR(i,N)
		{
			res.ar[i] += a.ar[i] + b.ar[i];
		}
		return res;
	}
	friend st operator - (const st &a, const st &b)
	{
		st res;
		FOR(i,N)
		{
			res.ar[i] += a.ar[i] - b.ar[i];
		}
		return res;
	}
};
int n;
st dp[150009];
char b[150009];
st v[50009];
int last[50009];
char ty[50009];
st def_res;
vector<vector<int> > g;
map<pair<int,int> ,int> mp;
int ID(pair<int,int> x)
{
	if (mp.find(x) == mp.end())
		mp[x] = mp.size();
	return mp[x] - 1;
}
st DP(int x, int pr)
{
	if (x < 0)
	{
		x = x;
	}
	int t = ID(MP(pr,x));
	if (g[x].size() == 1 && pr != -1)
	{
		b[t] = 1;
		return dp[t]=def_res;
	}
	if (b[t] == 1)
		return dp[t];
	else if (ty[x] == 1)
	{
		if (last[x] != -1)
		{
			v[x] = v[x] + DP(last[x], x);
		}
		if (pr != -1)
		{
			v[x] = v[x] - dp[ID(MP(x,pr))];
		}
		last[x] = pr;
		return dp[t] = v[x].inc();
	}
	st res;
	for (int i=0;i < g[x].size();i++)
	{
		if (g[x][i] == pr)
			continue;
		res = res + DP(g[x][i],x);
	}
	res.ar[0]++;
	b[t] = 1;
	ty[x] = 1;
	last[x] = pr;
	v[x] = res;
	return dp[t] = res.inc();
}
int K;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d%d",&n,&K);
	g.resize(n);
	def_res.ar[1]=1;
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	LL res = 0;
	int CC = 0;
	FOR(i,n)
	{
		if (i == 49008)
			CC = CC;
		res += CC =  DP(i,-1).ar[K+1];
		if (CC == 0)
			CC = CC;
	}
	cout << res/2 << endl;
	return 0;
}


//#pragma comment(linker,"/STACK
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

struct st
{
	static const int N = 500;
	int ar[N];
	st()
	{
		CL(ar,0);
	}
	st inc()
	{
		st res;
		FOR(i,N-1)
		{
			res.ar[i+1] = ar[i];
		}
		return res;
	}
	friend st operator + (const st &a, const st &b)
	{
		st res;
		FOR(i,N)
		{
			res.ar[i] += a.ar[i] + b.ar[i];
		}
		return res;
	}
	friend st operator - (const st &a, const st &b)
	{
		st res;
		FOR(i,N)
		{
			res.ar[i] += a.ar[i] - b.ar[i];
		}
		return res;
	}
};
int n;
st dp[100009];
char b[100009];
st v[50009];
int last[50009];
char ty[50009];
st def_res;
vector<vector<int> > g;
map<pair<int,int> ,int> mp;
int ID(pair<int,int> x)
{
	if (x.first == -1 || x.second == -1)
		return 100008;
	if (mp.find(x) == mp.end())
		mp[x] = mp.size();
	return mp[x] - 1;
}
st DP(int x, int pr)
{
	if (x < 0)
	{
		x = x;
	}
	int t = ID(MP(pr,x));
	if (g[x].size() == 1 && pr != -1)
	{
		b[t] = 1;
		return dp[t]=def_res;
	}
	if (b[t] == 1 && pr != -1)
		return dp[t];
	else if (ty[x] == 1)
	{
		if (last[x] != -1)
		{
			v[x] = v[x] + DP(last[x], x);
		}
		if (pr != -1)
		{
			v[x] = v[x] - DP(pr,x);//dp[ID(MP(x,pr))];
		}
		last[x] = pr;
		return dp[t] = v[x].inc();
	}
	st res;
	for (int i=0;i < g[x].size();i++)
	{
		if (g[x][i] == pr)
			continue;
		res = res + DP(g[x][i],x);
	}
	res.ar[0]++;
	b[t] = 1;
	ty[x] = 1;
	last[x] = pr;
	v[x] = res;
	return dp[t] = res.inc();
}
int K;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d%d",&n,&K);
	g.resize(n);
	def_res.ar[1]=1;
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	LL res = 0;
	int CC = 0;
	FOR(i,n)
	{
		if (i == 49008)
			CC = CC;
		res += CC =  DP(i,-1).ar[K+1];
		if (CC == 0)
			CC = CC;
	}
	cout << res/2 << endl;
	return 0;
}


//#pragma comment(linker,"/STACK
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

struct st
{
	static const int N = 502;
	int ar[N];
	st()
	{
		CL(ar,0);
	}
	st inc()
	{
		st res;
		FOR(i,N-1)
		{
			res.ar[i+1] = ar[i];
		}
		return res;
	}
	friend st operator + (const st &a, const st &b)
	{
		st res;
		FOR(i,N)
		{
			res.ar[i] += a.ar[i] + b.ar[i];
		}
		return res;
	}
	friend st operator - (const st &a, const st &b)
	{
		st res;
		FOR(i,N)
		{
			res.ar[i] += a.ar[i] - b.ar[i];
		}
		return res;
	}
};
int n;
st dp[100009];
char b[100009];
st v[50009];
int last[50009];
char ty[50009];
st def_res;
vector<vector<int> > g;
map<pair<int,int> ,int> mp;
int ID(pair<int,int> x)
{
	if (x.first == -1 || x.second == -1)
		return 100008;
	if (mp.find(x) == mp.end())
		mp[x] = mp.size();
	return mp[x] - 1;
}
st DP(int x, int pr)
{
	if (x < 0)
	{
		x = x;
	}
	int t = ID(MP(pr,x));
	if (g[x].size() == 1 && pr != -1)
	{
		b[t] = 1;
		return dp[t]=def_res;
	}
	if (b[t] == 1 && pr != -1)
		return dp[t];
	else if (ty[x] == 1)
	{
		if (last[x] != -1)
		{
			v[x] = v[x] + DP(last[x], x);
		}
		if (pr != -1)
		{
			v[x] = v[x] - DP(pr,x);//dp[ID(MP(x,pr))];
		}
		last[x] = pr;
		return dp[t] = v[x].inc();
	}
	st res;
	for (int i=0;i < g[x].size();i++)
	{
		if (g[x][i] == pr)
			continue;
		res = res + DP(g[x][i],x);
	}
	res.ar[0]++;
	b[t] = 1;
	ty[x] = 1;
	last[x] = pr;
	v[x] = res;
	return dp[t] = res.inc();
}
int K;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d%d",&n,&K);
	g.resize(n);
	def_res.ar[1]=1;
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	LL res = 0;
	int CC = 0;
	FOR(i,n)
	{
		if (i == 49008)
			CC = CC;
		res += CC =  DP(i,-1).ar[K+1];
		if (CC == 0)
			CC = CC;
	}
	cout << res/2 << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

int dp[50009][509];
int n,K;
vector<int> g[50009];
int DP(int x, int len)
{
	if (dp[x][len] != -1)
		return dp[x][len];
	int res = 0;
	FOR(i,g[x].size())
	{
		if(len > 0)
			res += DP(g[x][i],len-1);
	}
	if (len == 0)
		res++;
	return dp[x][len] = res;
}
void clean_dfs(int x, int pr)
{
	FOR(i,g[x].size())
	{
		if (g[x][i] == pr)
		{
			swap(g[x][i],g[x].back());
			g[x].pop_back();
			i--;
			continue;
		}
		clean_dfs(g[x][i],x);
	}
}

LL calc(int x)
{
	LL res = 0;
	FOR(i,g[x].size())
		res+=calc(g[x][i]);
	LL tres = 0;
	for (int i=1;i<K;i++)
	{
		FOR(j,g[x].size())
		{
			tres += (LL)DP(g[x][j],i-1) * (DP(x,K-i) - DP(g[x][j],K-i-1));
		}
	}
	tres/=2;
	res += tres;
	res += DP(x,K);
	return res;
}
int main()
{
	CL(dp,-1);
	//freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&K);
	//g.resize(n);
	FOR(i,n-1)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	clean_dfs(0,-1);
	cout << calc(0) << endl;
	return 0;
}


using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#undef FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const ll md=1000000007;

int dp[50001][501];

int main(){
    vint v[50001];
    int nson[50001]={},fath[50001];
    int n,k;

    cin>>n>>k;

    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[x].p_b(y);
        v[y].p_b(x);
    }

    qint q;
    q.push(1);
    bool ok[50001]={};
    ok[1]=1;

    while(!q.empty()){
        int i=q.front(); q.pop();

        for(uint j=0;j<v[i].size();j++)
            if(!ok[v[i][j]]){
                ok[v[i][j]]=1;
                nson[i]++;
                fath[v[i][j]]=i;
                q.push(v[i][j]);
            }
    }
    ll s=0;
    for(int i=1;i<=n;i++)
        if(!nson[i])
            q.push(i);

    while(!q.empty()){
        int i=q.front(); q.pop();

        dp[i][0]=1;
        for(uint j=0;j<v[i].size();j++){
            if(!nson[v[i][j]])
                for(int t=1;t<=k;t++)
                    dp[i][t]+=dp[v[i][j]][t-1];
        }
        nson[fath[i]]--;
        if(!nson[fath[i]]) q.push(fath[i]);

        for(int t=0;t<k/2;t++)
            s+=dp[i][t]*dp[i][k-t];
        if(k%2==0) s+=(dp[i][k/2]*(dp[i][k/2]-1))/2;
    }

    cout<<s;

    return 0;
}


using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#undef FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const ll md=1000000007;

int dp[50001][501];

int main(){
    vint v[50001];
    int nson[50001]={},fath[50001];
    int n,k;

    cin>>n>>k;

    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[x].p_b(y);
        v[y].p_b(x);
    }

    qint q;
    q.push(1);
    bool ok[50001]={};
    ok[1]=1;

    while(!q.empty()){
        int i=q.front(); q.pop();

        for(uint j=0;j<v[i].size();j++)
            if(!ok[v[i][j]]){
                ok[v[i][j]]=1;
                nson[i]++;
                fath[v[i][j]]=i;
                q.push(v[i][j]);
            }
    }
    ll s=0;
    for(int i=1;i<=n;i++)
        if(!nson[i])
            q.push(i);

    while(!q.empty()){
        int i=q.front(); q.pop();

        dp[i][0]=1;
        for(uint j=0;j<v[i].size();j++){
            if(!nson[v[i][j]])
                for(int t=1;t<=k;t++)
                    dp[i][t]+=dp[v[i][j]][t-1];
        }
        nson[fath[i]]--;
        if(!nson[fath[i]]) q.push(fath[i]);

        for(int t=0;t<k/2+k%2;t++)
            s+=dp[i][t]*dp[i][k-t];
        if(k%2==0) s+=(dp[i][k/2]*(dp[i][k/2]-1))/2;
    }

    cout<<s;

    return 0;
}


using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#undef FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const ll md=1000000007;

int dp[50001][501];

int main(){
    vint v[50001];
    int nson[50001]={},fath[50001];
    int n,k;

    cin>>n>>k;

    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[x].p_b(y);
        v[y].p_b(x);
    }

    qint q;
    q.push(1);
    bool ok[50001]={};
    ok[1]=1;

    while(!q.empty()){
        int i=q.front(); q.pop();

        for(uint j=0;j<v[i].size();j++)
            if(!ok[v[i][j]]){
                ok[v[i][j]]=1;
                nson[i]++;
                fath[v[i][j]]=i;
                q.push(v[i][j]);
            }
    }
    ll s=0;
    for(int i=1;i<=n;i++)
        if(!nson[i])
            q.push(i);;
    while(!q.empty()){
        int i=q.front(); q.pop();

        dp[i][0]=1;
        int dx[501]={};
        dx[0]=1;

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<=k;t++){
                    dp[i][t]+=dp[x][t-1];
                    dx[t]=dp[i][t];
                }
            }
        }

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<k;t++){
                    dx[t]-=dp[x][t-1];
                    s+=dx[t]*dx[k-t+1];
                }
            }
        }

        s+=dp[i][k];
        nson[fath[i]]--;
        if(!nson[fath[i]]) q.push(fath[i]);
    }

    cout<<s;

    return 0;
}


using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#unde FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const ll md=1000000007;

int dp[50001][501];

int main(){
    vint v[50001];
    int nson[50001]={},fath[50001];
    int n,k;

    cin>>n>>k;

    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[x].p_b(y);
        v[y].p_b(x);
    }

    qint q;
    q.push(1);
    bool ok[50001]={};
    ok[1]=1;

    while(!q.empty()){
        int i=q.front(); q.pop();

        for(uint j=0;j<v[i].size();j++)
            if(!ok[v[i][j]]){
                ok[v[i][j]]=1;
                nson[i]++;
                fath[v[i][j]]=i;
                q.push(v[i][j]);
            }
    }
    ll s=0;
    for(int i=1;i<=n;i++)
        if(!nson[i])
            q.push(i);;
    while(!q.empty()){
        int i=q.front(); q.pop();

        dp[i][0]=1;
        int dx[501]={};
        dx[0]=1;

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<=k;t++){
                    dp[i][t]+=dp[x][t-1];
                    dx[t]=dp[i][t];
                }
            }
        }

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<k;t++){
                    dx[t]-=dp[x][t-1];
                    s+=dx[t]*dp[x][k-t-1];
                }
            }
        }

        s+=dp[i][k];
        nson[fath[i]]--;
        if(!nson[fath[i]]) q.push(fath[i]);
    }

    cout<<s;

    return 0;
}


using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#undef FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const ll md=1000000007;

int dp[50001][501];

int main(){
    vint v[50001];
    int nson[50001]={},fath[50001];
    int n,k;

    cin>>n>>k;

    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[x].p_b(y);
        v[y].p_b(x);
    }

    qint q;
    q.push(1);
    bool ok[50001]={};
    ok[1]=1;

    while(!q.empty()){
        int i=q.front(); q.pop();

        for(uint j=0;j<v[i].size();j++)
            if(!ok[v[i][j]]){
                ok[v[i][j]]=1;
                nson[i]++;
                fath[v[i][j]]=i;
                q.push(v[i][j]);
            }
    }
    ll s=0;
    for(int i=1;i<=n;i++)
        if(!nson[i])
            q.push(i);;
    while(!q.empty()){
        int i=q.front(); q.pop();

        dp[i][0]=1;
        int dx[501]={};
        dx[0]=1;

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<=k;t++){
                    dp[i][t]+=dp[x][t-1];
                    dx[t]=dp[i][t];
                }
            }
        }

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<k;t++){
                    dx[t]-=dp[x][t-1];
                    s+=dx[t]*dp[x][k-t-1];
                }
            }
        }

        s+=dp[i][k];
        nson[fath[i]]--;
        if(!nson[fath[i]]) q.push(fath[i]);
    }

    cout<<s;

    return 0;
}


using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#undef FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const ll md=1000000007;

int dp[50001][501];

int main(){
    vint v[50001];
    int nson[50001]={},fath[50001];
    int n,k;

    cin>>n>>k;

    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[x].p_b(y);
        v[y].p_b(x);
    }

    qint q;
    q.push(1);
    bool ok[50001]={};
    ok[1]=1;

    while(!q.empty()){
        int i=q.front(); q.pop();

        for(uint j=0;j<v[i].size();j++)
            if(!ok[v[i][j]]){
                ok[v[i][j]]=1;
                nson[i]++;
                fath[v[i][j]]=i;
                q.push(v[i][j]);
            }
    }
    ll s=0;
    for(int i=1;i<=n;i++)
        if(!nson[i])
            q.push(i);

    while(!q.empty()){
        int i=q.front(); q.pop();

        dp[i][0]=1;
        int dx[501]={};
        dx[0]=1;

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<=k;t++){
                    dp[i][t]+=dp[x][t-1];
                    dx[t]=dp[i][t];
                }
            }
        }

        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<k;t++){
                    dx[t]-=dp[x][t-1];
                    s+=dx[t]*dx[k-t-1];
                }
            }
        }

        s+=dp[i][k];
        nson[fath[i]]--;
        if(!nson[fath[i]]) q.push(fath[i]);
    }

    cout<<s;

    return 0;
}


using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#undef FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const ll md=1000000007;

int dp[50001][501];

int main(){
    vint v[50001];
    int nson[50001]={},fath[50001];
    int n,k;

    cin>>n>>k;

    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[x].p_b(y);
        v[y].p_b(x);
    }

    qint q;
    q.push(1);
    bool ok[50001]={};
    ok[1]=1;

    while(!q.empty()){
        int i=q.front(); q.pop();

        for(uint j=0;j<v[i].size();j++)
            if(!ok[v[i][j]]){
                ok[v[i][j]]=1;
                nson[i]++;
                fath[v[i][j]]=i;
                q.push(v[i][j]);
            }
    }
    ll s=0;
    for(int i=1;i<=n;i++)
        if(!nson[i])
            q.push(i);

    while(!q.empty()){
        int i=q.front(); q.pop();

        dp[i][0]=1;
        for(uint j=0;j<v[i].size();j++){
            int x=v[i][j];
            if(!nson[x]){
                for(int t=1;t<=k;t++)
                    dp[i][t]+=dp[x][t-1];
                for(uint t=j+1;t<v[i].size();t++){
                    int y=v[i][t];
                    for(int l=1;l<=k-1;l++)
                        s+=dp[x][l-1]*dp[y][k-1-l];
                }
            }
        }
        s+=dp[i][k];
        nson[fath[i]]--;
        if(!nson[fath[i]]) q.push(fath[i]);
    }

    cout<<s;

    return 0;
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static int n, a, b;
	static ArrayList<Integer>[] graph;
	static long[] da, db;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		a = 0;
		b = Integer.parseInt(st.nextToken()) - 1;
		if (b == 0) {
			System.out.println(2);
			return;
		}
		da = new long[n];
		db = new long[n];
		Arrays.fill(da, Long.MAX_VALUE);
		Arrays.fill(db, Long.MAX_VALUE);
		graph = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			graph[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
			st = new StringTokenizer(br.readLine());
			int u = Integer.parseInt(st.nextToken()) - 1;
			int v = Integer.parseInt(st.nextToken()) - 1;
			graph[u].add(v);
			graph[v].add(u);
		}
		bfs(a, da);
		bfs(b, db);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (db[i] < da[i]) {
				ans = Math.max(ans, da[i]);
			}
		}
		System.out.println(2 * ans);
	}

	private static void bfs(int s, long[] d) {
		ArrayDeque<Integer> q = new ArrayDeque<>();
		q.add(s);
		d[s] = 0L;
		while (!q.isEmpty()) {
			int crt = q.pollFirst();
			for (int v : graph[crt]) {
				if (d[v] == Long.MAX_VALUE) {
					d[v] = d[crt] + 1;
					q.add(v);
				}
			}
		}
	}
}


/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins*****************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        Makegraph(n+1);
        for(int i=0;i<n-1;i++){
            st=br.readLine().split(" ");
            int a=Integer.parseInt(st[0]);
            int b=Integer.parseInt(st[1]);
            addEdge(a,b);
            addEdge(b,a);
        }
        int dp[]=new int[n+1];
        int max=1;
        Queue<Integer> q=new ArrayDeque<>();
        q.add(1);
        boolean vis[]=new boolean[n+1];
        vis[1]=true;
        while(!q.isEmpty()){
            int a=q.remove();
            max=Math.max(max,dp[a]);
            //debug(a);
            for(int u:graph[a]){
                if(!vis[u]){
                    vis[u]=true;
                    q.add(u);
                    dp[u]=dp[a]+1;
                }
            }
        }
        out.println(2*max);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000");
        out.println(ft.format(d));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }

/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }

    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}


/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins*****************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        Makegraph(n+1);
        for(int i=0;i<n-1;i++){
            st=br.readLine().split(" ");
            int a=Integer.parseInt(st[0]);
            int b=Integer.parseInt(st[1]);
            addEdge(a,b);
        }
        int dp[]=new int[n+1];
        int max=1;
        Queue<Integer> q=new ArrayDeque<>();
        q.add(1);
        while(!q.isEmpty()){
            int a=q.remove();
            max=Math.max(max,dp[a]);
            for(int u:graph[a]){
                q.add(u);
                dp[u]=dp[a]+1;
            }
        }
        out.println(2*max);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000");
        out.println(ft.format(d));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }

/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }

    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}


/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins*****************************************/
    static boolean vis[];
    static int parent[];
    static HashMap<Integer,Integer>map=new HashMap<>();
    static int max1=0;
    static int dfs2(int start,int lev){
        vis[start]=true;
        max1=Math.max(max1,lev);
        map.put(lev,start);
        int ans=0;
        for(int u:graph[start]){
            if(!vis[u])
            ans=Math.max(ans,dfs2(u,lev+1));
        }
        return ans+1;
    }
    static void dfs1(int start,int par,int dist[]){
        parent[start]=par;
        dist[start]=dist[par]+1;
        vis[start]=true;
        for(int u:graph[start]){
            if(!vis[u]){
                dfs1(u,start,dist);
            }
        }
    }
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        int x=Integer.parseInt(st[1]);
        Makegraph(n+1);
        for(int i=0;i<n-1;i++){
            st=br.readLine().split(" ");
            int a=Integer.parseInt(st[0]);
            int b=Integer.parseInt(st[1]);
            addEdge(a,b);
            addEdge(b,a);
        }
        int a=x;
        int dist[]=new int[n+1];
        vis=new boolean[n+1];
        parent=new int[n+1];

        dfs1(1,1,dist);
        ArrayList<Integer> path=new ArrayList<>();
        while(a!=1){
            path.add(a);
            a=parent[a];
        }
        Collections.reverse(path);
        int point=path.get(path.size()/2);
        int p1=dist[point];
        vis=new boolean[n+1];
        vis[parent[point]]=true;
        int max=dfs2(point,0);
     //   debug(point,max);

      //  debug(path);
     // debug(path);
     // debug(map);
        out.println(2*(dist[map.get(max1)]-1));

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000");
        out.println(ft.format(d));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }

/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }

    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}


/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins*****************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        Makegraph(n+1);
        for(int i=0;i<n-1;i++){
            st=br.readLine().split(" ");
            int a=Integer.parseInt(st[0]);
            int b=Integer.parseInt(st[1]);
            addEdge(a,b);
        }
        int dp[]=new int[n+1];
        int max=0;
        Queue<Integer> q=new ArrayDeque<>();
        q.add(1);
        while(!q.isEmpty()){
            int a=q.remove();
            max=Math.max(max,dp[a]);
            for(int u:graph[a]){
                q.add(u);
                dp[u]=dp[a]+1;
            }
        }
        out.println(2*max);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000");
        out.println(ft.format(d));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }

/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }

    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}