Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int n,k,visited[2001];
vi a(2001);
vi b(2001);
vi g(2001);

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        g[a[i]].pb(b[i]);
        g[b[i]].pb(a[i]);
    }
    int cur = 0;
    if(k%2==0)
    {
        for(int i = 1; i <= n; i++)
        {
            visited[i]=1;
            stack< ii >X;
            X.push(mp(i,0));
            while(!X.empty())
            {
                ii Y = X.top();
                X.pop();
                if(Y.se>(K/2))cur++;
                for(int j = 0; j < g[Y.fi].size(); j++)
                {
                    if(visited[g[Y.fi][j]]==0)
                    {
                        X.push(mp(g[Y.fi][j],Y.se+1));
                        visited[g[Y.fi][j]] = 1;
                    }
                }
            }
        }
    }
    else
    {
        for(int i = 1; i <= n; i++)
        {
            visited[a[i]]=1;
            visited[b[i]]=1;
            stack< ii >X;
            X.push(mp(a[i],0));
            X.push(mp(b[i],0));
            while(!X.empty())
            {
                ii Y = X.top();
                X.pop();
                if(Y.se>(K-1/2))cur++;
                for(int j = 0; j < g[Y.fi].size(); j++)
                {
                    if(visited[g[Y.fi][j]]==0)
                    {
                        X.push(mp(g[Y.fi][j],Y.se+1));
                        visited[g[Y.fi][j]] = 1;
                    }
                }
            }
        }
    }
    cout << cur << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:12: error: request for member 'push_back' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)a.std::vector<int>::operator[](((std::vector<int>::size_type)i))))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   11 | #define pb push_back
      |            ^~~~~~~~~
a.cc:39:17: note: in expansion of macro 'pb'
   39 |         g[a[i]].pb(b[i]);
      |                 ^~
a.cc:11:12: error: request for member 'push_back' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)b.std::vector<int>::operator[](((std::vector<int>::size_type)i))))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   11 | #define pb push_back
      |            ^~~~~~~~~
a.cc:40:17: note: in expansion of macro 'pb'
   40 |         g[b[i]].pb(a[i]);
      |                 ^~
a.cc:54:26: error: 'K' was not declared in this scope
   54 |                 if(Y.se>(K/2))cur++;
      |                          ^
a.cc:55:44: error: request for member 'size' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)Y.std::pair<int, int>::first))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   55 |                 for(int j = 0; j < g[Y.fi].size(); j++)
      |                                            ^~~~
a.cc:57:39: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   57 |                     if(visited[g[Y.fi][j]]==0)
      |                                       ^
a.cc:59:42: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   59 |                         X.push(mp(g[Y.fi][j],Y.se+1));
      |                                          ^
a.cc:60:40: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   60 |                         visited[g[Y.fi][j]] = 1;
      |                                        ^
a.cc:79:26: error: 'K' was not declared in this scope
   79 |                 if(Y.se>(K-1/2))cur++;
      |                          ^
a.cc:80:44: error: request for member 'size' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)Y.std::pair<int, int>::first))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   80 |                 for(int j = 0; j < g[Y.fi].size(); j++)
      |                                            ^~~~
a.cc:82:39: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   82 |                     if(visited[g[Y.fi][j]]==0)
      |                                       ^
a.cc:84:42: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   84 |                         X.push(mp(g[Y.fi][j],Y.se+1));
      |                                          ^
a.cc:85:40: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   85 |                         visited[g[Y.fi][j]] = 1;
      |                                        ^