Language: C++

//
/*
ID: kfoozmi1
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

#ifdef kfoozminus
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu() {
	cerr << endl;
}

template <typename T>
void faltu(T a[], int n) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename First, typename ... hello>
void faltu(First arg, const hello&... rest) {
	cerr << arg << ' ';
	faltu(rest...);
}
#else
#define dbg(args...)
#endif

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define SQR(a) ((a) * (a))
#define vsort(v) sort(v.begin(), v.end())
#define PQ priority_queue
#define PI acos(-1)
#define EPS 1e-9

#define B1 43
#define B2 43

#define MOD1 1000000007
#define MOD2 1000000009
#define MOD  1000000007

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//int dx[] = {0, 0, +1, -1};
//int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool checkBit(ll n, int i) { return n & (1LL << i); }
inline ll setBit(ll n, int i) { return n | (1LL << i); }
inline ll resetBit(ll n, int i) { return n & (~ (1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }
inline double dist(double ix, double iy, double jx, double jy) { return sqrt(SQR(ix - jx) + SQR(iy - jy)); }

#define PMX 1000000

int marked[PMX/64+2];

#define mark(x) marked[x>>6] |= (1<<((x&63)>>1))
#define check(x) (marked[x>>6] & (1<<((x&63)>>1)))

bool isPrime(int x)
{
    return (x>1) && ((x==2) || ((x&1) && (!(check(x)))));
}

void seive(int n)
{
    int i, j;
    for(i=3; i*i<=n; i+=2)
    {
        if(!check(i))
        {
            for(j=i*i; j<=n; j+=i<<1)
            {
                mark(j);
            }
        }
    }
}

ll bigMod(ll a, ll b)
{
	ll r = 1;
	while(b) {
		if(b & 1) (r *= a) %= MOD;
		b >>= 1;
		(a *= a) %= MOD;
	}
	return r;
}

#define INF 100000000
#define MX 100007

vector<int> edge[MX];
int s;
pii n1, n2;
vector<int> v[2] (m, 0);

pii dfs(int i, int pre)
{
	pii ret = {0, i};
	for(int k = 0; k < edge[i].size(); k ++) {

		if(edge[i][k] == pre) continue;
		pii p = dfs(edge[i][k], i);
		if(ret.F < p.F) ret = p;
	}
	ret.F ++;
	return ret;
}

int m, f;

void dfs2(int i, int j, int pre)
{
	v[f][m - j] ++;
	if(j == m) return ;
	for(int k = 0; k < edge[i].size(); k ++) {

		if(edge[i][k] == pre) continue;
		dfs2(edge[i][k], j + 1, i);
	}
	//v[f].PB(edge[i].size() - (i != s));
}

int main()
{
#ifdef kfoozminus
	//freopen("in", "r", stdin);
#endif
	int n, k, i, sum, ans, u, x;
	scanf("%d %d", &n, &k);
	for(i = 1; i < n; i ++) {

		scanf("%d %d", &u, &x);
		edge[u].PB(x);
		edge[x].PB(u);
	}
	n1 = dfs(1, -1);
	n2 = dfs(n1.S, -1);
	n2.F --;
	if(n2.F <= k) printf("0\n");
	else {
		k = n2.F - k;
		dbg(k);
		m = n2.F;

		f = 0;
		s = n1.S;
		dfs2(n1.S, 0, -1);

		f = 1;
		s = n2.S;
		dfs2(n2.S, 0, -1);

		for(i = 1; i < v[0].size(); i ++) v[0][i] += v[0][i - 1];
		for(i = 1; i < v[1].size(); i ++) v[1][i] += v[1][i - 1];

		for(i = 0; i < v[0].size(); i ++) {

			/*dbg(i, v[0][i]);
			dbg(i, v[1][i]);*/
		}

		ans = INF;

		for(i = 0; i <= k; i ++) {
			
			sum = 0;
			if(i) sum += v[0][i - 1];
			if(k - i) sum += v[1][(k - i) - 1];

			ans = min(sum, ans);
		}

		printf("%d\n", ans);
	}
        return 0;
}


Compiler output:
a.cc:108:19: error: 'm' was not declared in this scope
  108 | vector<int> v[2] (m, 0);
      |                   ^
a.cc:108:23: error: expression list treated as compound expression in initializer [-fpermissive]
  108 | vector<int> v[2] (m, 0);
      |                       ^