Language: C++

//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


const int N = 100002;
int n, subsize[N], parent_[N];
vector<ii> adj[N];


void dfs(int v, int par){
    subsize[v] = 1;
    parent_[v] = par;
    for(auto it : adj[v])
        if(it.ff != par){
            dfs(it.ff, v);
            subsize[v] += subsize[it.ff];
        }
}


int main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    int e = n-1;
    while(e--){
        int a, b, c;
        cin>>a>>b>>c;
        adj[a].pb(ii(b, c));
        adj[b].pb(ii(a, c));
    }

    dfs(1, -1);

// cout<<"subsize: ";for(int i=1;i<=n;i++) cout<<subsize[i]<<" ";cout<<endl;

    ll minval = 1e15, yolo = -1;
    ll ans = 0;
    for(int i=1;i<=n;i++)
        for(auto it : adj[i])
            if(it.ff > i){
                ll s = min(subsize[i], subsize[it.ff]);
                s = min(s, n-s);
                ans += 2LL * s * it.ss;
// cout<<"now at "<<i<<" "<<it.ff<<":"<<it.ss<<" "<<s<<endl;
                minval = min(minval, it.ss);
            }

    for(int i=1;i<=n;i++)
        if(2*subsize[i] == n){
            for(auto it : adj[i])
                if(it.ff == parent_[i]){
                    cout<<ans-it.ss;
                    return 0;
                }
        }

    cout<<ans - minval;
    return 0;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:69:29: error: no matching function for call to 'min(ll&, int&)'
   69 |                 minval = min(minval, it.ss);
      |                          ~~~^~~~~~~~~~~~~~~
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:2:
/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:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   69 |                 minval = min(minval, it.ss);
      |                          ~~~^~~~~~~~~~~~~~~
/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:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   69 |                 minval = min(minval, it.ss);
      |                          ~~~^~~~~~~~~~~~~~~