Language: C++

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=2e5+100;
vector <int> g[N];
ll dp[N][2];

ll dfs(ll v,ll p){
    ll p1=0;
    for (int i=0;i<g[v].size();i++){
        ll u=g[v][i];
        if (u==p){
            continue;
        }
        dfs(u,v);
        dp[v][1]+=dp[u][1];
        if (dp[u][1]==0){
            p1++;
        }
    }
    p1=max(p1-1,(ll)0);
    dp[v][1]+=p1;
    p1=0;
    vector <pair <int,pii> > a;
    for (int i=0;i<g[v].size();i++){
        ll u=g[v][i];
        if (u==p){
            continue;
        }
        p1=0;
        if (dp[u][1]==0){
            p1++;
        }
        a.pb({dp[u][0]-dp[u][1]-p1,{dp[u][1]-p1,u}});
    }
    sort(a.begin(),a.end());
    if (a.size()){
        dp[v][0]+=dp[a[0].S.S][0];
        for (int i=1;i<a.size();i++){
            dp[v][0]+=dp[a[i].S.S][1];
            if (dp[a[i].S.S][1]!=0){
                continue;
            }
            dp[v][0]++;
        }
    }
    dp[v][0]=min(dp[v][0],dp[v][1]+1);
    dp[v][0]=max(dp[v][0],(ll)1);
    dp[v][1]=min(dp[v][1],dp[v][0]);

    //cout << v << " " << dp[v][0] << " " << dp[v][1] << endl;
}
int32_t main(){
    ll n;
    cin >> n;
    ll ans=0;
    for (int i=0;i<n-1;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    //cout << ans+1 << endl;
    vector <int> b;
    for (int i=0;i<n;i++){
        if (g[i].size()==1){
            b.pb(i);
        }
    }

    ll mi=1e9+100;
    for (int i=0;i<min((ll)10,(10)b.size());i++){
        ll v=b[i];
        dfs(v,v);
        mi=min(mi,dp[g[v][0]][1]+1);
    }
    cout << mi;
}


Compiler output:
a.cc: In function 'll dfs(ll, ll)':
a.cc:62:1: warning: no return statement in function returning non-void [-Wreturn-type]
   62 | }
      | ^
a.cc: In function 'int32_t main()':
a.cc:82:35: error: expected ')' before 'b'
   82 |     for (int i=0;i<min((ll)10,(10)b.size());i++){
      |                       ~           ^
      |                                   )
a.cc:82:23: error: no matching function for call to 'min(ll, int)'
   82 |     for (int i=0;i<min((ll)10,(10)b.size());i++){
      |                    ~~~^~~~~~~~~~~~~
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:82:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |     for (int i=0;i<min((ll)10,(10)b.size());i++){
      |                    ~~~^~~~~~~~~~~~~
/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:82:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |     for (int i=0;i<min((ll)10,(10)b.size());i++){
      |                    ~~~^~~~~~~~~~~~~