criyle/codenet-compile-errors huggingface dataset:
Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#include<unordered_map>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2000 + 47;

int U[MAX];
vector<int> g[MAX];
int n, k;
int cnt = 0;

void fill(int A[], int val)
{
	FOR(i, 0, MAX) A[i] = val;
}

void dfs(int v, int d)
{
	if (d > k / 2) return;
	//cout << "*" << v + 1 << ": " << d << endl;
	cnt++;
	U[v] = 1;

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		if (!U[to]) dfs(to, d + 1);
	}
}

int calc(int i)
{
	fill(U, 0);
	cnt = 0;
	dfs(i, 0);
	//cout << "?? " << i + 1 << " " << cnt << endl;
	int maxx = 0;
	int ind = -1;
	if (k % 2)
	{
		FOR(j, 0, n)
		{
			if (U[j])
			{
				int c = 0;
				FOR(k, 0, SZ(g[j]))
				{
					if (!U[g[j][k]])
					{
						c++;
					}
				}

				if (maxx < c)
				{
					maxx = c;
					ind = j;
				}
			}
		}

		FOR(i, 0, SZ(g[ind])) U[g[ind][i]] = 1;
	}

	return cnt + maxx;
}

int D[MAX];

void dfs1(int v, int p, int d)
{
	D[v] = d;
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		if (U[to] && D[to] == -1) dfs1(to, v, d + 1);
	}
}

bool check(int v)
{
	fill(D, -1);
	dfs1(v, -1, 0);
	int maxx = v;
	FOR(i, 0, n)
	{
		if (D[i] > D[maxx]) maxx = i;
	}

	FILL(D, -1);
	dfs1(maxx, -1, 0);
	FOR(i, 0, n)
	{
		if (D[i] > D[maxx]) maxx = i;
	}

	if (D[maxx] <= k) return true;
	return false;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	FOR(i, 0, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	if (k == 1)
	{
		cout << n - 2 << endl;
		return 0;
	}

	int ans = INF;
	int ind = -1;
	FOR(i, 0, n)
	{
		int cnt = calc(i);
		if (ans > n - cnt)
		{
			ans = n - cnt;
			ind = i;
		}
	}

	calc(ind);
	if (!check(ind))
	{
		//cout << "-------------" << endl;
		throw - 1;
	}

	cout << ans << endl;
}


Compiler output:
a.cc: In function 'bool check(int)':
a.cc:26:23: error: 'memset' was not declared in this scope
   26 | #define FILL(a,value) memset(a, value, sizeof(a))
      |                       ^~~~~~
a.cc:126:9: note: in expansion of macro 'FILL'
  126 |         FILL(D, -1);
      |         ^~~~
a.cc:19:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   18 | #include<list>
  +++ |+#include <cstring>
   19 | #include <sstream>
Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#include<unordered_map>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2000 + 47;

int U[MAX];
vector<int> g[MAX];
vector<int> V1, V2, V;
int n, k;
int cnt = 0;
void dfs(int v, int d)
{
	if (d > k / 2) return;
	//cout << "*" << v + 1 << ": " << d << endl;
	cnt++;
	U[v] = 1;

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		if (!U[to]) dfs(to, d + 1);
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	FOR(i, 0, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int ans = INF;
	if (k % 2 == 0)
	{
		FOR(i, 0, n)
		{
			FILL(U, 0);
			cnt = 0;
			dfs(i, 0);
			//cout << "?? " << i + 1 << " " << cnt << endl;
			ans = min(ans, n - cnt);
		}

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

	FOR(i, 0, n)
	{
		FILL(U, 0);
		cnt = 0;
		dfs(i, 0);
		//cout << "?? " << i + 1 << " " << cnt << endl;
		int maxx = 0;
		FOR(j, 0, n)
		{
			int c = 0;
			if (U[j])
			{
				FOR(k, 0, SZ(g[j]))
				{
					if (!U[g[j][k]]) c++;
				}
			}

			maxx = max(maxx, c);
		}

		ans = min(ans, n - cnt - maxx);
	}

	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:23: error: 'memset' was not declared in this scope
   26 | #define FILL(a,value) memset(a, value, sizeof(a))
      |                       ^~~~~~
a.cc:83:25: note: in expansion of macro 'FILL'
   83 |                         FILL(U, 0);
      |                         ^~~~
a.cc:19:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   18 | #include<list>
  +++ |+#include <cstring>
   19 | #include <sstream>
a.cc:26:23: error: 'memset' was not declared in this scope
   26 | #define FILL(a,value) memset(a, value, sizeof(a))
      |                       ^~~~~~
a.cc:96:17: note: in expansion of macro 'FILL'
   96 |                 FILL(U, 0);
      |                 ^~~~
a.cc:26:23: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   26 | #define FILL(a,value) memset(a, value, sizeof(a))
      |                       ^~~~~~
a.cc:96:17: note: in expansion of macro 'FILL'
   96 |                 FILL(U, 0);
      |                 ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int n, k;
vector<int> edge[2002];
int ans = 2147483647;
int search(int now, int dis, int last) {
    int ans = 0;
    if (dis < 0) ans ++;
    for (int i = 0; i < edge[now].size(); i ++)
    if (edge[now][i] != last) {
        ans += search(edge[now][i], dis - 1, now);
    }
    return ans;
}
int main() {
    scanf("%d %d", &n, &k);
    for (int i = 1; i < n; i ++) {
        int x, y;
        scanf("%d %d", &x, &y);
        edge[x].push_back(y); edge[y].push_back(x);
    }
    if (k & 1)
        //for (int i = 1; i <= n; i ++) ans = min(ans, search(i, (k - 1) / 2, 0));
    else
        for (int i = 1; i <= n; i ++) ans = min(ans, search(i, k / 2, 0));
    printf("%d", ans);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:5: error: expected primary-expression before 'else'
   24 |     else
      |     ^~~~
a.cc:25:25: error: 'i' was not declared in this scope
   25 |         for (int i = 1; i <= n; i ++) ans = min(ans, search(i, k / 2, 0));
      |                         ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,k,w[N],head[N],next[N];
void add(int f,int t){
    static int cnt=0;
    w[++cnt]=t;
    next[cnt]=head[f];
    head[f]=cnt;
}
int ans,cnt,dep[N],num[N];
void dfs(int x,int fa){
    if (dep[x]<=k/2) cnt++;
    num[x]=0;
    if (dep[x]==k/2+1) num[x]++;
    for (int i=head[x];i;i=next[i]){
        int v=w[i];
        if (v==fa) continue;
        dep[v]=dep[x]+1;
        dfs(v,x);
        num[x]+=num[v];
    }
}
int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    for (int v=1;v<=n;v++){
        dep[v]=cnt=0;
        dfs(v,0);
        if (k&1){
            int Max=0;
            for (int i=head[v];i;i=next[i]) Max=max(Max,num[w[i]]);
            cnt+=Max;
        }
        ans=max(ans,cnt);
    }
    printf("%d\n",n-ans);
    return 0;
}


Compiler output:
a.cc: In function 'void add(int, int)':
a.cc:8:5: error: reference to 'next' is ambiguous
    8 |     next[cnt]=head[f];
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'int next [100010]'
    4 | int n,k,w[N],head[N],next[N];
      |                      ^~~~
a.cc: In function 'void dfs(int, int)':
a.cc:16:28: error: reference to 'next' is ambiguous
   16 |     for (int i=head[x];i;i=next[i]){
      |                            ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'int next [100010]'
    4 | int n,k,w[N],head[N],next[N];
      |                      ^~~~
a.cc: In function 'int main()':
a.cc:37:36: error: reference to 'next' is ambiguous
   37 |             for (int i=head[v];i;i=next[i]) Max=max(Max,num[w[i]]);
      |                                    ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'int next [100010]'
    4 | int n,k,w[N],head[N],next[N];
      |                      ^~~~
Language: C++

#include<cstdio>
#include<algorithm>
#include<cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=5e3+5;
const int inf=1e9;
int n,m,head[N],next[N],go[N],sum;
int dis[2005][2005],tot;
inline void add(int x,int y)
{
	go[++tot]=y;
	next[tot]=head[x];
	head[x]=tot;
}
inline void dfs(int x,int fa,int dep)
{
	if (dep>(m/2))sum++;
	for(int i=head[x];i;i=next[i])
	{
		int v=go[i];
		if (v!=fa)
		{
			dfs(v,x,dep+1);
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	fo(i,1,n-1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	int ans=inf;
	fo(i,1,n)
	{
		sum=0;
		dfs(i,0,0);
		ans=min(ans,sum);
	}
	printf("%d\n",ans);
} 

Compiler output:
a.cc: In function 'void add(int, int)':
a.cc:14:9: error: reference to 'next' is ambiguous
   14 |         next[tot]=head[x];
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:17: note:                 'int next [5005]'
    9 | int n,m,head[N],next[N],go[N],sum;
      |                 ^~~~
a.cc: In function 'void dfs(int, int, int)':
a.cc:20:31: error: reference to 'next' is ambiguous
   20 |         for(int i=head[x];i;i=next[i])
      |                               ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:17: note:                 'int next [5005]'
    9 | int n,m,head[N],next[N],go[N],sum;
      |                 ^~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <utility>
#include <list>
#include <ctime>
#include <memory>

using namespace std;

const int N=2050;
vector<int> E[N];

int DFS(int x,int p,int d,int mx)
{
	int ans=1;
	if(d!=mx){
		for(int y=0;y<E[x].size();y++){
			if(E[x][y]==p)continue;
			ans+=DFS(E[x][y],x,d+1,mx);
		}
	}
	return ans;
}

int main()
{
	int n,k;
	cin >>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin >>a>>b;
		a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	int ans=0;
	if(k%2==0){
		for(int v=0;v<n;v++){
			ans=max(ans,DFS(v,-1,0,k/2));
		}
	}
	else {
		for(int v=0;v<n;v++){
			for(int u=0;u<E[v].size();u++){
				ans=max(ans,DFS(E[v][u],u,0,k/2)+DFS(u,E[v][u],0,k/2));
			}
		}
	}
	
	ans=n-ans;
	if(and<0)ans=0; 
	cout << ans;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:15: error: expected identifier before '<' token
   61 |         if(and<0)ans=0;
      |               ^
Language: C++

#include <iostream>
//#include <algorithm>
//#include <cmath>
#include <vector>
//#include <stdlib.h>
#include <queue>
//#include <set> 
//#include <string>
//#include <string.h>
//#include <cstring>
//#include <stdio.h>
//#include <fstream>
//#include <stack>
//#include <iomanip>
//#include <conio.h>
//#include <windows.h>
//#include <time.h>
//#define rep(N) for(int i=0;i<N;i++)
//#define ll long long 
//#define pii pair<int,int>
//#define For(I,N) for(int I=0;I<N;I++)
#define rep(N) for(int i=0;i<N;i++)
using namespace std;
vector <int> vec[2005];
vector <pair<int,int> >num[2005];
bool visit[2005];
int leaf[2005];
int dist[2005][2005];
int n,k;
vector <int> leave;
void bfs(int);

void bfs(int x)
{
	fill(visit,visit+n,0);
	int t=x;
	queue<pair<int,int> >que;
	que.push(make_pair<int,int>(1,0));
	while(!que.empty())
	{
		int nx=que.front().first;
		int s=que.front().second;
		que.pop();
		for(int i=0;i<vec[nx].size();i++)
		{
			if(visit[vec[nx][i]]) continue;
			visit[vec[nx][i]]=true;
			dist[t][vec[nx][i]]=s+1;
			que.push(make_pair<int,int>(vec[nx][i],s+1));
		}
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>k;
	int x,y;
	rep(n-1)
	{
		cin>>x>>y;
		vec[--x].push_back(--y);
		vec[y].push_back(x);
		leaf[x]++;
		leaf[y]++;
	}
	for(int i=0;i<n;i++)
	{
		bfs(i);
	}
//	rep(n)
//	{
//		dist[i][i]=0;
//		for(int j=0;j<n;j++)
//		{
//			cout<<dist[i][j]<<"  ";
//		}
//		cout<<endl;
//	}
	int s=0,mini=0;
	bool ok[n];
	fill(ok,ok+n,0);
	rep(n)
	{
		dist[i][i]=0;
		if(ok[i]) continue;
		for(int j=0;j<n;j++)
		{
			if(ok[j]==1) continue;
			if(dist[i][j]>k) ok[j]=1;
		}
	}
	rep(n)
	{
		s+=ok[i];
	}
	cout<<s<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'void bfs(int)':
a.cc:49:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   49 |                         que.push(make_pair<int,int>(vec[nx][i],s+1));
      |                                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:1132:21: note:   initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]'
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |               ~~~~~~^~~
Language: C++

#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
using namespace std;
typedef long long ll;
int n,k;
const int N=4008;
vector<int> g[N];
const int INF=(int)1e7+10;
int ans=N;
int q[4008];
int topQ;
int dist[4008];
inline void bfs()
{
	for(int k=0;k<topQ;k++)
	{
		int v=q[k];
		for(int u : g[v])
		{
			int w=dist[v]+2;
			if(dist[u]<=w)
				continue;
			dist[u]=w;
			q[topQ++]=u;
		}
	}
	return;
}
int solvedian(int v)
{
	for(int i=0;i<n;i++)
		dist[i]=INF;
	dist[v]=0;
	topQ=0;
	q[topQ++]=v;
	bfs();
	int res=0;
	for(int i=0;i<n;i++)
		if(dist[i]>k)
			res++;
	return res;
}
int solvebian()
{
	for(int i=0;i<n;i++)
		dist[i]=INF;
	dist[v]=dist[u]=1;
	topQ=0;
	q[topQ++]=v;
	q[topQ++]=u;
	bfs();
	int res=0;
	for(int i=0;i<n;i++)
		if(dist[i]>k)
			res++;
	return res;
}
int main ()
{
	cin>>n>>k;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>v>>u;
		v--;
		u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	for(int v=0;v<n;v++)
		ans=min(ans,solvedian(v));
	for(int v=0;v<n;v++)
		for(int u:g[v])
			if(u>v)
				ans=min(ans,solvebian(v,u));
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int solvebian()':
a.cc:61:14: error: 'v' was not declared in this scope
   61 |         dist[v]=dist[u]=1;
      |              ^
a.cc:61:22: error: 'u' was not declared in this scope
   61 |         dist[v]=dist[u]=1;
      |                      ^
a.cc: In function 'int main()':
a.cc:89:54: error: too many arguments to function 'int solvebian()'
   89 |                                 ans=min(ans,solvebian(v,u));
      |                                             ~~~~~~~~~^~~~~
a.cc:57:5: note: declared here
   57 | int solvebian()
      |     ^~~~~~~~~
Language: C++

#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
using namespace std;
typedef long long ll;
int n,k;
const int N=4008;
vector<int> g[N];
const int INF=(int)1e7+10;
int ans=N;
int q[4008];
int topQ;
int dist[4008];
inline void bfs()
{
	for(int k=0;k<topQ;k++)
	{
		int v=q[k];
		for(int u : g[v])
		{
			int w=dist[v]+2;
			if(dist[u]<=w)
				continue;
			dist[u]=w;
			q[topQ++]=u;
		}
	}
	return;
}
int solvedian()
{
	for(int i=0;i<n;i++)
		dist[i]=INF;
	dist[v]=0;
	topQ=0;
	q[topQ++]=v;
	bfs();
	int res=0;
	for(int i=0;i<n;i++)
		if(dist[i]>k)
			res++;
	return res;
}
int solvebian()
{
	for(int i=0;i<n;i++)
		dist[i]=INF;
	dist[v]=dist[u]=1;
	topQ=0;
	q[topQ++]=v;
	q[topQ++]=u;
	bfs();
	int res=0;
	for(int i=0;i<n;i++)
		if(dist[i]>k)
			res++;
	return res;
}
int main ()
{
	cin>>n>>k;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>v>>u;
		v--;
		u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	for(int v=0;v<n;v++)
		ans=min(ans,solvedian(v));
	for(int v=0;v<n;v++)
		for(int u:g[v])
			if(u>v)
				ans=min(ans,solvebian(v,u));
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int solvedian()':
a.cc:47:14: error: 'v' was not declared in this scope
   47 |         dist[v]=0;
      |              ^
a.cc: In function 'int solvebian()':
a.cc:61:14: error: 'v' was not declared in this scope
   61 |         dist[v]=dist[u]=1;
      |              ^
a.cc:61:22: error: 'u' was not declared in this scope
   61 |         dist[v]=dist[u]=1;
      |                      ^
a.cc: In function 'int main()':
a.cc:85:38: error: too many arguments to function 'int solvedian()'
   85 |                 ans=min(ans,solvedian(v));
      |                             ~~~~~~~~~^~~
a.cc:43:5: note: declared here
   43 | int solvedian()
      |     ^~~~~~~~~
a.cc:89:54: error: too many arguments to function 'int solvebian()'
   89 |                                 ans=min(ans,solvebian(v,u));
      |                                             ~~~~~~~~~^~~~~
a.cc:57:5: note: declared here
   57 | int solvebian()
      |     ^~~~~~~~~
Language: C++

#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
using namespace std;
typedef long long ll;
int n,k;
const int N=4008;
vector<int> g[N];
const int INF=(int)1e7+10;
int ans=N;
int q[4008];
int topQ;
int dist[4008];
inline void bfs()
{
	for(int k=0;k<topQ;k++)
	{
		int v=q[k];
		for(int u : g[v])
		{
			int w=dist[v]+2;
			if(dist[u]<=w)
				continue;
			dist[u]=w;
			q[topQ++]=u;
		}
	}
	return;
}
int solvedian()
{
	for(int i=0;i<n;i++)
		dist[i]=INF;
	dist[v]=0;
	topQ=0;
	q[topQ++]=v;
	bfs();
	itn res=0;
	for(int i=0;i<n;i++)
		if(dist[i]>k)
			res++;
	return res;
}
int solvebian()
{
	for(int i=0;i<n;i++)
		dist[i]=INF;
	dist[v]=dist[u]=1;
	topQ=0;
	q[topQ++]=v;
	q[topQ++]=u;
	bfs();
	int res=0;
	for(int i=0;i<n;i++)
		if(dist[i]>k)
			res++;
	return res;
}
int main ()
{
	cin>>n>>k;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>v>>u;
		v--;
		u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	for(int v=0;v<n;v++)
		ans=min(ans,solvedian(v));
	for(int v=0;v<n;v++)
		for(int u:g[v])
			if(u>v)
				ans=min(ans,solvebian(v,u));
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int solvedian()':
a.cc:47:14: error: 'v' was not declared in this scope
   47 |         dist[v]=0;
      |              ^
a.cc:51:9: error: 'itn' was not declared in this scope; did you mean 'int'?
   51 |         itn res=0;
      |         ^~~
      |         int
a.cc:54:25: error: 'res' was not declared in this scope
   54 |                         res++;
      |                         ^~~
a.cc:55:16: error: 'res' was not declared in this scope
   55 |         return res;
      |                ^~~
a.cc: In function 'int solvebian()':
a.cc:61:14: error: 'v' was not declared in this scope
   61 |         dist[v]=dist[u]=1;
      |              ^
a.cc:61:22: error: 'u' was not declared in this scope
   61 |         dist[v]=dist[u]=1;
      |                      ^
a.cc: In function 'int main()':
a.cc:85:38: error: too many arguments to function 'int solvedian()'
   85 |                 ans=min(ans,solvedian(v));
      |                             ~~~~~~~~~^~~
a.cc:43:5: note: declared here
   43 | int solvedian()
      |     ^~~~~~~~~
a.cc:89:54: error: too many arguments to function 'int solvebian()'
   89 |                                 ans=min(ans,solvebian(v,u));
      |                                             ~~~~~~~~~^~~~~
a.cc:57:5: note: declared here
   57 | int solvebian()
      |     ^~~~~~~~~
Language: C++

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <functional>
#include <map>
#include <ios>
#include <iosfwd>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <complex.h>
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#include <conio.h>
#include <numeric>
#include <list>
#include <windows.h>
#include <cfloat>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int n,k,sz,q[2010],dist[2010],ans=1e9;
vector<int> pos[2010];

inline void bfs()
{
	for(int i=0;i<sz;i++)
	{
		int cur=q[i];
		for(int j:pos[cur])
		{
			int w=dist[cur]+2;
			if(dist[j]<=w) continue;
			dist[j]=w;
			q[sz++]=j;
		}
	}
}

inline int solveVertex(int i)
{
	fill(dist,dist+n,1e9);
	dist[i]=0;
	sz=0;
	
	q[sz++]=i;
	bfs();
	int sum=0;
	for(int j=0;j<n;j++) if(dist[j]>k) sum++;
	
	return sum;
}

inline int solveEdge(int i,int j)
{
	fill(dist,dist+n,1e9);
	dist[i]=dist[j]=1;
	sz=0;
	
	q[sz++]=i;
	q[sz++]=j;
	bfs();
	int sum=0;
	for(int m=0;m<n;m++) if(dist[m]>k) sum++;
	
	return sum;
}

int main()
{
	cin>>n>>k;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		pos[a].push_back(b);
		pos[b].push_back(a);
	}
	
	for(int i=0;i<n;i++) ans=min(ans,solveVertex(i));
	for(int i=0;i<n;i++)
		for(int j:pos[i])
			if(j>i) ans=min(ans,solveEdge(i,j));
	
	cout<<ans;
	
	return 0;
}

Compiler output:
a.cc:53:10: fatal error: conio.h: No such file or directory
   53 | #include <conio.h>
      |          ^~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int n,k;
vector<int> nei[2050];
int dis[2050][2050];
bool crash[2050][2050];
int cnum[2050]; 
void bfs(int root){
	queue<int> q;
	dis[root][root]=0;
	q.push(root); 
	while(!q.empty()){
		int last=q.front();
		q.pop();
		for(int i=0;i<nei[last].size();i++){
			if(dis[root][nei[last][i]]==-1){
				dis[root][nei[last][i]]=dis[root][last]+1;
				q.push(nei[last][i]);
			}
		}
	}
}
bool nocrash(){
	for(int i=0;i<n;i++){
		if(cnum[i]>0) return false;
	}
	return true;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			dis[i][j]=-1;
		}
	}
	for(int i=0;i<n;i++){
		bfs(i);
	}
	for(int i=0;i<n;i++){
		int num=0;
		for(int j=0;j<n;j++){
			if(dis[i][j]>k){
				crash[i][j]=true;
				num++;
			}
		}
		cnum[i]=num;
	}
	while(!nocrash()){
		int mx=-1,imx=-1;
		for(int i=0;i<n;i++){
			if(cnum[i]>mx){
				mx=cnum[i];
				imx=i;
			}
		}
		for(int i=0;i<n;i++){
			 crash[imx][i]=false;
			 if(crash[i][imx]){
			 	crash[i][imx]=false;
			 	cnum[i]--;
			 }
		}
		cnum[imx]=-2;
		ans++;
	}
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:95:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   95 |                 ans++;
      |                 ^~~
      |                 abs
a.cc:97:15: error: 'ans' was not declared in this scope; did you mean 'abs'?
   97 |         cout<<ans;
      |               ^~~
      |               abs
Language: C++

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

int n,k;
vector<int> adj[2005];



int bfs(int v,int r,int prv=-1){
	if(r>0){
		int sum=1;
		for(int i=0;i<adj[v].size();i++){
			if(adj[v][i]!=prv){
				int s=bfs(adj[v][i],r-1,v);
				sum+=s;
			}
		}
	return sum;
	}
	else return 1;	
}



int main(){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n-1;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	if(k%2==0){
		int r=k/2,mint=1e6;
		for(int i=1;i<=n;i++){
			mint=min(mint,n-bfs(i,r));
		}
		printf("%d\n",mint);
	}
	else{
		int r=k/2,mint=1e6;
		for(int i=1;i<=n;i++){
                        int maxm=0
			for(int j=0;j<adj[i].size();j++){
				maxm=max(maxm,bfs(i,r)-bfs(adj[i][j],r-1,i)+bfs(adj[i][j],r,i));
			}
                        mint=min(mint,n-maxm>0?n-maxm:0);
		}
		printf("%d\n",mint);
	}
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:62:25: error: expected ',' or ';' before 'for'
   62 |                         for(int j=0;j<adj[i].size();j++){
      |                         ^~~
a.cc:62:37: error: 'j' was not declared in this scope
   62 |                         for(int j=0;j<adj[i].size();j++){
      |                                     ^
Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <queue>
#include <set> 
#include <string>
#include <string.h>
#include <cstring>
#include <stdio.h>
#include <fstream>
#include <stack>
#include <iomanip>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define rep(N) for(int i=0;i<N;i++)
#define ll long long 
#define pii pair<int,int>
#define For(I,N) for(int I=0;I<N;I++)
#define rep(N) for(int i=0;i<N;i++)
using namespace std;
vector <int> vec[2005];
vector <pair<int,int> >num[2005];
bool visit[2005];
int leaf[2005];
int dist[2005][2005];
int n,k;
vector <int> leave;

void bfs(int x)
{
	fill(visit,visit+n,0);
	queue <pair<int,int> >que;
	que.push(make_pair<int,int>(x,0));
	while(!que.empty())
	{
		int nx=que.front().first;
		int s=que.front().second;
		que.pop();
		for(int i=0;i<vec[nx].size();i++)
		{
			if(visit[vec[nx][i]]) continue;
			visit[vec[nx][i]]=true;
			dist[x][vec[nx][i]]=s+1;
			que.push(make_pair<int,int>(vec[nx][i],s+1));
		}
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>k;
	int x,y;
	rep(n-1)
	{
		cin>>x>>y;
		vec[--x].push_back(--y);
		vec[y].push_back(x);
		leaf[x]++;
		leaf[y]++;
	}
	rep(n)
	{
		bfs(i);
	}
//	rep(n)
//	{
//		dist[i][i]=0;
//		for(int j=0;j<n;j++)
//		{
//			cout<<dist[i][j]<<"  ";
//		}
//		cout<<endl;
//	}
	int s=0,mini=0;
	bool ok[n];
	fill(ok,ok+n,0);
	rep(n)
	{
		dist[i][i]=0;
		if(ok[i]) continue;
		for(int j=0;j<n;j++)
		{
			if(ok[j]==1) continue;
			if(dist[i][j]>k) ok[j]=1;
		}
	}
	rep(n)
	{
		s+=ok[i];
	}
	cout<<s<<endl;
	return 0;
}

Compiler output:
a.cc:15:10: fatal error: conio.h: No such file or directory
   15 | #include <conio.h>
      |          ^~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
using namespace std;
typedef long long ll;
int N,K;
int cnt=0;
vector<int> vec;
vector<int> vt;
map<int,int> mp;
int maxN=2000;
int a[2005],b[2005];
set<int> s;
int main ()
{
	cin>>N>>K;
	for(int i=1;i<maxN;i++)
	{	
		cin>>a[i]>>b[i];
		mp[(long long)b[i]]=a[i];
		s.insert(mp[b[i]]);cnt++;
		cnt.push_back(vec);
	}
	sort(vec.begin(),vec.end());
	int q=vec.max;
	if(q>K) cout<<q-K;
	else cout<<0
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:21: error: request for member 'push_back' in 'cnt', which is of non-class type 'int'
   35 |                 cnt.push_back(vec);
      |                     ^~~~~~~~~
a.cc:38:19: error: 'class std::vector<int>' has no member named 'max'
   38 |         int q=vec.max;
      |                   ^~~
a.cc:40:21: error: expected ';' before 'return'
   40 |         else cout<<0
      |                     ^
      |                     ;
   41 |         return 0;
      |         ~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>

using namespace std;
/**==Info==
*Program:1
*Problem:Shorten Diameter
*Date:2017-8-8
*Algorithm:DFS
*Stats:Unknown*/
int n,k;
vector<int> nei[2050];
int dis[2050][2050];
bool crash[2050][2050];
int cnum[2050];  //Crash Number
void bfs(int root){
	queue<int> q;
	dis[root][root]=0;
	q.push(root); 
	while(!q.empty()){
		int last=q.front();
		q.pop();
		for(int i=0;i<nei[last].size();i++){
			if(dis[root][nei[last][i]]==-1){
				dis[root][nei[last][i]]=dis[root][last]+1;
				q.push(nei[last][i]);
				//cout<<"Push yoU!"<<endl;
			}
		}
	}
}

bool nocrash(){
	for(int i=0;i<n;i++){
		if(cnum[i]>0) return false;
	}
	return true;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	
	memset(dis,-1,2050*2050);
	
	for(int i=0;i<n;i++){
		bfs(i);
	}
	
//	for(int i=0;i<n;i++){
//		for(int j=0;j<n;j++){
//			cout<<dis[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	//Find crash
	for(int i=0;i<n;i++){
		int num=0;
		for(int j=0;j<n;j++){
			if(dis[i][j]>k){
				crash[i][j]=true;
				num++;
			}
		}
		cnum[i]=num;
	}
	
//	cout<<"Oops"<<endl;
	
	int ans=0;
//			for(int i=0;i<n;i++){
//			cout<<cnum[i]<<" ";
//		}
//		cout<<endl;
		
	while(!nocrash()){
		//Find the biggest crasher!!!!
		int mx=-1,imx=-1;
		for(int i=0;i<n;i++){
			if(cnum[i]>mx){
				mx=cnum[i];
				imx=i;
			}
		}
		
		//Then Kill It
		for(int i=0;i<n;i++){
			 crash[imx][i]=false;
			 if(crash[i][imx]){
			 	crash[i][imx]=false;
			 	cnum[i]--;
			 }
		}
		cnum[imx]=-2;
		ans++;
		

	}
	cout<<ans;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:9: error: 'memset' was not declared in this scope
   67 |         memset(dis,-1,2050*2050);
      |         ^~~~~~
a.cc:21:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   20 | #include <functional>
  +++ |+#include <cstring>
   21 |
Language: C++

#include <bits/stdc++.h>
#define ll long long
#define uint unsigned long long
#define ls x << 1
#define rs x << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int inf = 1e9;
vector<int>g[2010];
int dp[2010][2010], dp2[2010][2010], K, v[2010];
void dfs(int x, int fa)
{
	v[x] = 1;
	int s = (int)g[x].size();
	rep(i, 0, s - 1)
	{
		if(fa == g[x][i])continue;
		dfs(g[x][i], x);
		v[x] += v[g[x][i]];
	}
	rep(i, 0, s)
		rep(j, 0, K)
			dp2[i][j] = -inf;
	dp2[0][0] = 1;
	int sz = 0, now = 0;
	rep(i, 0, s - 1)
	{
		if(fa == g[x][i]) continue;
		rep(j, 0, sz)
		{
			dp2[now + 1][j] = max(dp2[now + 1][j], dp2[now][j]);
			for(int k = 0; j + k + 1 <= K; k ++)
				dp2[now + 1][max(j, k + 1)] = max(dp2[now + 1][max(j, k + 1)], dp2[now][j] + dp[g[x][i]][k]);
		}
		now ++;
		sz += v[g[x][i]];
	}
	rep(i, 0, K) dp[x][i] = dp2[now][i];
}
int main()
{
	int n, k;
	n = read();
	k = read();
	K = k;
	rep(i, 1, n - 1)
	{
		int u, v;
		u = read();
		v = re	ad();
		u --, v --;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1);
	int ret = 0;
	rep(i, 0, n - 1)
		rep(j, 0, k)
			ret = max(ret, dp[i][j]);
	printf("%d\n", n - ret);
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:67:21: error: 're' was not declared in this scope; did you mean 'rs'?
   67 |                 v = re  ad();
      |                     ^~
      |                     rs
Language: C++

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int N,K;
int dp[1005][1005];
int maxi[1005];
int s[1005];
int nr[1005];
vector<int> G[1005];
void dfs(int nod,int tata)
{
    dp[nod][0]=1;
    maxi[nod]=nr[nod]=1;
    for(auto it:G[nod]){if(tata!=it){dfs(it,nod)nr[nod]+=nr[it];};}
    for(auto it:G[nod])
        if(tata!=it)
        {
            fill_n(s+1,K+1,1<<30);
            s[0]=dp[nod][0]+dp[it][0];
            for(int j=0;j<=maxi[it]&&j<K+1;j++)
                for(int k=1;k<=maxi[nod]&&k<=K+1-j;k++)
                    s[max(k,j+1)]=min(s[max(k,j+1)],dp[nod][k]+dp[it][j]);
            for(int i=1;i<=K+1;i++)s[i]=min(s[i-1],s[i]);
            memcpy(dp[nod],s,sizeof(s));
            maxi[nod]=max(maxi[nod],maxi[it]+1);
        }
}
int main()
{
    cin>>N>>K;
    for(int i=1;i<N;i++)
    {
        int a,b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1,0);
    int ans=1<<30;
    for(int i=1;i<=N;i++)
        for(int j=0;j<=K+1;j++)
            ans=min(ans,dp[i][j]+nr[1]-nr[j]);
    cout<<ans;
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:16:49: error: expected ';' before 'nr'
   16 |     for(auto it:G[nod]){if(tata!=it){dfs(it,nod)nr[nod]+=nr[it];};}
      |                                                 ^~
      |                                                 ;
Language: C++

# include <iostream>
# include <vector>
# define DIM 2010
using namespace std;
vector<int> Lista[DIM];
int Marcat[DIM],f[DIM],n,k,x,y,i,sol,maxim;
void dfs(int nc){
    for(int i=0;i<Lista[nc].size();i++){
        int nv=Lista[nc][i];
        if(Marcat[nv]==0){
            Marcat[nv]=Marcat[nc]+1;
            dfs(nv);
        }
    }
}
int main () {
    cin>>n>>k;
    for(i=1;i<n;i++){
        cin>>x>>y;
        Lista[x].push_back(y);
        Lista[y].push_back(x);
    }
    for(;;){
        for(i=1;i<=n;i++)
            Marcat[i]=f[i];
        Marcat[1]=1;
        maxim=0;
        dfs(1);
        for(i=1;i<=n;i++)
            if(maxim<Marcat[i]){
                maxim=Marcat[i];
                x=i;
            }
        for(i=1;i<=n;i++)
            Marcat[i]=f[i];
        Marcat[x]=1;
        maxim=0;
        dfs(x);
        for(i=1;i<=n;i++)
            if(maxim<Marcat[i]){
                maxim=Marcat[i];
                y=i;
            }
        maxim--;
        if(maxim<=k){
            cout<<sol<<"\n";
            return 0;
        }
        sol++;
        f[x]=-1;
        fout<<x<<"\n";
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:51:9: error: 'fout' was not declared in this scope
   51 |         fout<<x<<"\n";
      |         ^~~~
Language: C++

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

ll N, K;

ll walk_even(ll node, vector<ll> es[], ll depth, vector<bool> use){
	use[node] = true;
	ll ret = 0;
	for(ll next : es[node]){
		if(!use[next]) ret += walk_even(next, es, depth+1, use);
	}
	if(depth > K/2) ret++;
	return ret;
}


signed main(){
	cin >> N >> K;
	vector<P> es_odd;
	vector<ll> es_even[N];
	rep(N-1){
		ll from, to;
		cin >> from >> to;
		from--; to--;
		es_odd.push_back(P(from, to));
		es_even[from].push_back(to);
		es_even[to].push_back(from);
	}

	vector<ll> ans;
	if(K % 2 == 0){
		rep(N){
			ans.push_back(walk_even(i, es_even, 0, vector<bool>(N, false)));
		}
	}else{
		rep(P e : es_odd){
			vector<bool> use(N, false);
			use[e.second] = true;
			tmp1 = walk_even(e.first, es_even, 0, use);
			use[e.second] = false; use[e.first] = true;
			tmp2 = walk_even(e.second, es_even, 0, use);
			ans.push_back(min(tmp1, tmp2));
		}
	}
	cout << *min_element(all(ans));
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:28: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   13 | #define rep(n) for(int i=0;i<n;i++)
      |                            ^
a.cc:60:17: note: in expansion of macro 'rep'
   60 |                 rep(P e : es_odd){
      |                 ^~~
a.cc:60:23: error: expected primary-expression before 'e'
   60 |                 rep(P e : es_odd){
      |                       ^
a.cc:13:30: note: in definition of macro 'rep'
   13 | #define rep(n) for(int i=0;i<n;i++)
      |                              ^
a.cc:13:35: error: expected ';' before ')' token
   13 | #define rep(n) for(int i=0;i<n;i++)
      |                                   ^
a.cc:60:17: note: in expansion of macro 'rep'
   60 |                 rep(P e : es_odd){
      |                 ^~~
a.cc:62:29: error: 'e' was not declared in this scope
   62 |                         use[e.second] = true;
      |                             ^
a.cc:63:25: error: 'tmp1' was not declared in this scope; did you mean 'tm'?
   63 |                         tmp1 = walk_even(e.first, es_even, 0, use);
      |                         ^~~~
      |                         tm
a.cc:65:25: error: 'tmp2' was not declared in this scope; did you mean 'tm'?
   65 |                         tmp2 = walk_even(e.second, es_even, 0, use);
      |                         ^~~~
      |                         tm
Language: C++

#include<algorithm>
#include<iostream>
#include<vector>
#include<utility>
#define INF 10000
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
enum { MaxEdge = 2000 };
int dist[MaxEdge][MaxEdge];

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> edge[MaxEdge];
	memset(dist, INF, sizeof(dist));
	vector<pair<int, int>> E;
	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		dist[a][b] = 1;
		dist[b][a] = 1;
		E.push_back(P(a, b));
	}
	for (int i = 0; i < n; i++) {
		dist[i][i] = 0;
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	if (k % 2 == 0) {
		int ans = INF;
		for (int i = 0; i < n; i++) {
			int a = 0;
			for (int j = 0; j < n; j++) {
				if (dist[i][j] > k/2)a++;
			}
			ans = min(ans, a);
		}
		cout << ans << endl;
	}
	else {
		int ans = INF;
		for (int i = 0; i < E.size(); i++) {
			int a = 0;
			for (int j = 0; j < n; j++) {
				if (dist[E[i].first][j] > k/2&&dist[E[i].second][j]>k/2) {
					a++;
				}
			}
			ans = min(ans, a);
		}
		cout << ans << endl;
	}

}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:9: error: 'memset' was not declared in this scope
   16 |         memset(dist, INF, sizeof(dist));
      |         ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include<utility>
  +++ |+#include <cstring>
    5 | #define INF 10000
Language: C++

#include <bits/stdc++.h>
#define N 2002
#define PB push_back
#define MP make_pair
#define F first
#define S second
using namespace std;
int n, m, k, i, j, l, r, t, fix[N], fox[N], a[N][N], d, ans;
vector<int>v[N];
queue<int>q;
int main() {
    cin>>n>>k;
    if(k==1){
        cout<n-2<<endl;
        return 0;
    }
    for(i=0;i<n-1;i++){
        cin>>l>>r;
        v[r].PB(l);
        v[l].PB(r);
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++)fix[j]=-1;
        fix[i]=0;
        q.push(i);
        while(q.size()){
            t=q.front();
            q.pop();
            d=max(d,a[i][t]);
            for(j=0;j<v[t].size();j++){
                if(fix[v[t][j]]!=-1)continue;
                q.push(v[t][j]);
                a[i][v[t][j]]=fix[v[t][j]]=a[i][t]+1;
            }
        }
    }
    //for(i=1;i<=n;i++){for(j=1;j<=n;j++)cout<<a[i][j]<<" ";cout<<endl;}
    if(k>=d){cout<<0<<endl;return 0;}
    if(k%2==1){
        m=1;
        for(j=1;j<=n;j++){
            if(a[i][j]==k/2){
                if(m<v[j].size())m=v[j].size();
            }
        }
        m--;
    }
    for(i=1;i<=n;i++){
        t=0;
        for(j=1;j<=n;j++){
            if(a[i][j]<=k/2)t++;
        }
        if(k%2==1)t+=m;
        ans=max(ans,t);
    }
    ans=n-ans;
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:17: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'
   14 |         cout<n-2<<endl;
      |              ~~~^~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int NMAX = 2000 + 5;

int n, k;
int h[NMAX];
int sz[NMAX];

int dp[NMAX][NMAX]; //dp[node][h] = numarul minim de noduri care trebuie
                    //eliminate pentru a obtine inaltimea maxim h in
                    //subarborele lui node

int dp2[NMAX][NMAX]; //dp[son][h] = numarul minim de noduri care trebuie
                     //eliminate dintre nodurile de pana la fiul son      
                     //(exclusiv) astfel incat inaltimea maxima sa fie h,
                     //iar diametrul sa nu depaseasca k

vector <int> graph[NMAX];

void upd(int &where, int val) {
    if (val < where)
        where = val;
}

void dfs(int node, int father) {
    if (father)
        graph[node].erase(find(graph[node].begin(), graph[node].end(), father));
    
    h[node] = 0;
    sz[node] = 1;
    for (auto it: graph[node]) {
        dfs(it, node);
        if (h[it] > h[node])
            h[node] = h[it];
        sz[node] += sz[it];
    }

    ++ h[node];

    int max_h = 0;
    for (int son = 0; son < static_cast <int>(graph[node].size()); ++ son) {
        for (int j = 0; j <= max(max_h, h[graph[node][son]]); ++ j)
            dp2[son + 1][j] = NMAX;

        for (int j = 0; j <= max_h && j <= k + 1; ++ j) {
            for (int l = 0; l <= h[graph[node][son]]; ++ l) {
                if (j + l <= k)
                    upd(dp2[son + 1][max(j, l)], dp[graph[node][son]][l] + dp2[son][j]);
            }
        }

        max_h = max(max_h, h[graph[node][son]]);
    }
    
    dp[node][0] = sz[node];
    for (int j = 0; j < h[node] && j <= K; ++ j)
        dp[node][j + 1] = dp2[graph[node].size()][j];
}

int main() {
    cin >> n >> k;

    int a, b;
    for (int i = 1; i < n; ++ i) {
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(1, 0);

    int ans = NMAX;

    for (int root = 1; root <= n; ++ root) {
        int current = NMAX;
        
        for (int l = 0; l <= k + 1; ++ l)
            upd(current, dp[root][l]);
        upd(ans, n - sz[root] + current);
    }

    cout << ans << '\n';

    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:60:41: error: 'K' was not declared in this scope
   60 |     for (int j = 0; j < h[node] && j <= K; ++ j)
      |                                         ^