Language: C++

#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> ii;

int n;
vector<ii> al[100005];
long long sz[100005];
long long ans;

int minus=1000000000;

void dfs(int i,int p){
    sz[i]=1;
    for (auto &it:al[i]){
        if (it.first==p) continue;
        
        dfs(it.first,i);
        ans+=2LL*min(sz[it.first],n-sz[it.first])*it.second;
        sz[i]+=sz[it.first];
        
        if (sz[it.first]*2==n) minus=it.second;
    }
}

void dfs2(int i,int p){
    for (auto &it:al[i]){
        if (it.first==p) continue;
        if (sz[it.first]>((n-1)/2)){
            dfs(it.first,i);
            return;
        }
    }
    
    for (auto &it:al[i]){
        minus=min(minus,it.second);
    }
}

int main(){
    scanf("%d",&n);
    int a,b,c;
    for (int x=1;x<n;x++){
        scanf("%d%d%d",&a,&b,&c);a
        al[a].push_back(ii(b,c));
        al[b].push_back(ii(a,c));
        minus=min(minus,c);
    }
    dfs(1,-1);
    if (minus==1000000000) dfs2(1,-1);
    
    printf("%lld\n",ans-minus);
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:23:32: error: reference to 'minus' is ambiguous
   23 |         if (sz[it.first]*2==n) minus=it.second;
      |                                ^~~~~
In file included from /usr/include/c++/14/bits/refwrap.h:39,
                 from /usr/include/c++/14/vector:68,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:12:5: note:                 'int minus'
   12 | int minus=1000000000;
      |     ^~~~~
a.cc: In function 'void dfs2(int, int)':
a.cc:37:9: error: reference to 'minus' is ambiguous
   37 |         minus=min(minus,it.second);
      |         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:12:5: note:                 'int minus'
   12 | int minus=1000000000;
      |     ^~~~~
a.cc:37:19: error: reference to 'minus' is ambiguous
   37 |         minus=min(minus,it.second);
      |                   ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:12:5: note:                 'int minus'
   12 | int minus=1000000000;
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:45:35: error: expected ';' before 'al'
   45 |         scanf("%d%d%d",&a,&b,&c);a
      |                                   ^
      |                                   ;
   46 |         al[a].push_back(ii(b,c));
      |         ~~                         
a.cc:48:9: error: reference to 'minus' is ambiguous
   48 |         minus=min(minus,c);
      |         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:12:5: note:                 'int minus'
   12 | int minus=1000000000;
      |     ^~~~~
a.cc:48:19: error: reference to 'minus' is ambiguous
   48 |         minus=min(minus,c);
      |                   ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:12:5: note:                 'int minus'
   12 | int minus=1000000000;
      |     ^~~~~
a.cc:51:9: error: reference to 'minus' is ambiguous
   51 |     if (minus==1000000000) dfs2(1,-1);
      |         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:12:5: note:                 'int minus'
   12 | int minus=1000000000;
      |     ^~~~~
a.cc:53:25: error: reference to 'minus' is ambiguous
   53 |     printf("%lld\n",ans-minus);
      |                         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:12:5: note:                 'int minus'
   12 | int minus=1000000000;
      |     ^~~~~