Language: C++

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& vec){
    os << "[";
    for(const auto& v : vec){
        os << v << ",";
    }
    os << "]";
    return os;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N,K;
    cin >> N >> K;
    vector<vector<int>> G(N,vector<int>(N));
    vector<int> A(N-1),B(N-1);
    rep(i,N-1){
        int a,b;cin>>a>>b;
        a--;
        b--;
        A[i]=a;
        B[i]=b;
        G[a].PB(b);
        G[b].PB(a);
    }

    if(K%2==0){
        cerr << "case1" << endl;
        int ans = INF;
        rep(i,N){
            // 点iからの距離を求める
            queue<int> que;
            vector<int> d(N,INF);
            d[i]=0;
            que.push(i);
            while(!que.empty()){
                int q = que.front();
                que.pop();
                rep(j,G[q].size()){
                    int nx = G[q][j];
                    if(d[nx]!=INF) continue;
                    d[nx] = d[q]+1;
                    que.push(nx);
                }
            }
            int cnt=0;
            rep(j,N) if(d[j]>K/2) cnt++;
            //cerr << i << endl;
            //cerr << d << endl;
            ans = min(ans,cnt);
        }
        cout << ans << endl;
    }else{
        int ans=INF;
        rep(i,N-1){
            int s=A[i],t=B[i];
            vector<int> ds(N,INF);
            queue<int> que;
            que.push(s);
            ds[s]=0;
            int t=0;
            while(!que.empty()){
                t++;
                if(t>4000) assert(false);
                int q = que.front();
                que.pop();
                rep(j,G[q].size()){
                    int nx = G[q][j];
                    if(ds[nx]!=INF) continue;
                    ds[nx]=ds[q]+1;
                    que.push(nx);
                }
            }

            vector<int> dt(N,INF);
            dt[t]=0;
            que.push(t);
            t=0;
            while(!que.empty()){
                t++;
                if(t>4000) assert(false);
                int q = que.front();
                que.pop();
                rep(j,G[q].size()){
                    int nx=G[q][j];
                    if(dt[nx]!=INF) continue;
                    dt[nx]=dt[q]+1;
                    que.push(nx);
                }
            }
            int cnt=0;
            rep(j,N){
                int d=min(ds[j],dt[j]);
                if(d>(K-1)/2) cnt++;
            }
            ans = min(ans,cnt);
        }
        cout << ans << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:82:17: error: redeclaration of 'int t'
   82 |             int t=0;
      |                 ^
a.cc:77:24: note: 'int t' previously declared here
   77 |             int s=A[i],t=B[i];
      |                        ^