Language: C++

#include <bits/stdc++.h>

using namespace std;

#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define type(x) __typeof(x.begin())

#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair

#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9 + 9;
const int N = 2e5 + 5;

int n, m, x, y, z, t, k, q, dp[N], a[N];
vector< int > v[N];
int ans;

int solve(int node, int root) {
    int mx1 = 0, mx2 = 0;
    foreach(it, v[node])
        if(*it != root) {
            int t = solve(*it, node) + 1;
            if(t >= mx1) {
                mx2 = mx1;
                mx1 = t;
            }
            else if(mx2 < t)
                mx2 = t;
        }
    if(mx1 + mx2 > k) {
        ans++;
        return -1;
    } return mx1;
}

int main() {
    scanf("%d %d", &n, &k);
    FOR(i, 2, n) {
        scanf("%d %d", &x, &y);
        v[x].pb(y);
        v[y].pb(x);
    }
    ll a = inf;
    FOR(i, 1, n) {
        ans = 0;
        solve(i, 0);
        a = min(a, ans);
    } cout << a << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:69:16: error: no matching function for call to 'min(ll&, int&)'
   69 |         a = min(a, ans);
      |             ~~~^~~~~~~~
In file included 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_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:69:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   69 |         a = min(a, ans);
      |             ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:69:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   69 |         a = min(a, ans);
      |             ~~~^~~~~~~~