Language: C++

// see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip
/// --- .lumrc Template {{{ ///
// #define DEBUG
// #define assert(...)
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = tuple<ll, ll>;
using P3 = tuple<ll, ll, ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;

#define omajinai ios::sync_with_stdio(false),cin.tie(0)

#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define FORI(i,a,b) for(int i=int(a);i<=int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPI(i,n) FORI(i,0,n)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPI(i,n) RFORI(i,0,n)

#define ALL(a) begin(a),end(a)
#define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end())
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define REACH(i,c) RREP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

#define BR cout<<"\n";

#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
#else
#define dump(...)
#endif

#define YES(x) cout<<((x)?"YES":"NO")<<"\n";
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n";
#define yes(x) cout<<((x)?"yes":"no")<<"\n";

int __int_temp; ll __ll_temp; string __string_temp;
#define oini (omajinai, cin>>__int_temp, __int_temp)
#define oinl (omajinai, cin>>__ll_temp, __ll_temp)
#define oins (omajinai, cin>>__string_temp, __string_temp)
#define ini (cin>>__int_temp, __int_temp)
#define inl (cin>>__ll_temp, __ll_temp)
#define ins (cin>>__string_temp, __string_temp)

#define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w)

#define fi(x) (get<0>(x))
#define se(x) (get<1>(x))
#define th(x) (get<2>(x))
#define fo(x) (get<3>(x))
#define fif(x) (get<4>(x))

template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != (int)v.size()-1 ? ", " : ""); o << "}";  return o; }

template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }

template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; }

template<typename T> inline int intlog2(T x);
template<> inline int intlog2(int x) { return x == 0 ? 0 : 32 - __builtin_clz(x); }
template<> inline int intlog2(ll x) { return x == 0 ? 0 : 64 - __builtin_clzll(x); }

constexpr double PI = acos(-1);

/// }}}--- ///

constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr int MOD = 1e9+7;

const int N = 2001;
VI g[N];

int dist[2][N];
int size[2][N];

void dfs(int x, int i, int p = -1, int d = 0) {
  dist[x][i] = d;
  for(int j : g[i]) if(j != p)
    dfs(x, j, i, d+1);
}

int dfs2(int x, int i, int p = -1) {
  int c = 1;
  for(int j : g[i]) if(j != p) {
    c += dfs2(x, j, i);
  }
  return size[x][i] = c;
}

int n=ini, k=ini;
VP treeone;

bool dfs3(int i, int to, int p = -1) {
  if(i == to) {
    treeone.emplace_back(size[0][i], size[1][i]);
    return 1;
  }
  bool ecasdqina = 0;
  for(int j : g[i]) if(p != j) {
    ecasdqina |= dfs3(j, to, i);
  }
  if(ecasdqina) {
    treeone.emplace_back(size[0][i], size[1][i]);
  }
  return ecasdqina;
}

int main() {
  REP(i, n-1) {
    int a=ini-1,b=ini-1;
    g[a].PB(b);
    g[b].PB(a);
  }
  dfs(0, 0);
  int noel = 0;
  REP(i, n) if(dist[0][noel] < dist[0][i]) noel = i;
  dfs(1, dist[0][noel]);
  int taplis = 0;
  REP(i, n) if(dist[1][taplis] < dist[1][i]) taplis = i;

  dfs2(0, noel);
  dfs2(1, taplis);

  dfs3(noel, taplis);
  
  ll ans = LINF;
  dump(treeone);
  for(int i=0; i + k < (int) treeone.size(); i++) {
    int j = i + k;
    ll tmp = 0;
    tmp += fi(treeone[i]) - 1;
    tmp += se(treeone[j]) - 1;
    smin(ans, tmp);
  }
  if(ans == LINF) ans = 0;


Compiler output:
a.cc: In function 'int dfs2(int, int, int)':
a.cc:105:10: error: reference to 'size' is ambiguous
  105 |   return size[x][i] = c;
      |          ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:5:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:92:5: note:                 'int size [2][2001]'
   92 | int size[2][N];
      |     ^~~~
a.cc: In function 'bool dfs3(int, int, int)':
a.cc:113:26: error: reference to 'size' is ambiguous
  113 |     treeone.emplace_back(size[0][i], size[1][i]);
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:92:5: note:                 'int size [2][2001]'
   92 | int size[2][N];
      |     ^~~~
a.cc:113:38: error: reference to 'size' is ambiguous
  113 |     treeone.emplace_back(size[0][i], size[1][i]);
      |                                      ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:92:5: note:                 'int size [2][2001]'
   92 | int size[2][N];
      |     ^~~~
a.cc:121:26: error: reference to 'size' is ambiguous
  121 |     treeone.emplace_back(size[0][i], size[1][i]);
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:92:5: note:                 'int size [2][2001]'
   92 | int size[2][N];
      |     ^~~~
a.cc:121:38: error: reference to 'size' is ambiguous
  121 |     treeone.emplace_back(size[0][i], size[1][i]);
      |                                      ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:92:5: note:                 'int size [2][2001]'
   92 | int size[2][N];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:153:27: error: expected '}' at end of input
  153 |   if(ans == LINF) ans = 0;
      |                           ^
a.cc:126:12: note: to match this '{'
  126 | int main() {
      |            ^