Language: C++

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define int long long
int x[100005],y[100005],z[100005];
struct edge
{
    int y;
    edge * next;
};
edge * li[100005];
edge * new_edge()
{
    static edge a[200005];
    static int top=0;
    return &a[top++];
}
void inserts(int x,int y)
{
    edge * t=new_edge();
    t->y=y;
    t->next=li[x];
    li[x]=t;
}
void insert_edge(int x,int y)
{
    inserts(x,y);
    inserts(y,x);
}
int size[100005];
bool vis[100005];
void dfs(int x)
{
    edge * t;
    size[x]=1;
    vis[x]=true;
    for (t=li[x];t!=0;t=t->next)
    {
        if (vis[t->y]) continue;
        dfs(t->y);
        size[x]+=size[t->y];
    }
}
int sizes(int x,int y)
{
    if (size[x]>size[y]) swap(x,y);
    return min(size[x],size[0]-size[x]);
}
bool size2(int x,int y)
{
    if (size[x]>size[y]) swap(x,y);
    return (size[x])==(size[0]-size[x]);
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    memset(li,0,sizeof(li));
    int n;
    scanf("%d",&n);
    int i;
    for (i=1;i<n;i++)
    {
        scanf("%d%d%d",&x[i],&y[i],&z[i]);
        x[i]--;
        y[i]--;
        insert_edge(x[i],y[i]);
    }
    memset(vis,0,sizeof(vis));
    dfs(0);
    long long ans=0;
    for (i=1;i<n;i++)
    {
        ans+=2*sizes(x[i],y[i])*(long long)z[i];
    }
    int mini=999999999;
    long long lost=0;
    for (i=1;i<n;i++)
    {
        if (size2(x[i],y[i])) lost+=z[i];
        mini=min(mini,z[i]);
    }
    if (lost!=0) cout<<ans-lost<<endl; else cout<<ans-mini<<endl;
    return 0;
} 


Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:52:5: error: reference to 'size' is ambiguous
   52 |     size[x]=1;
      |     ^~~~
In file included from /usr/include/c++/14/set:65,
                 from a.cc:1:
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:58:9: error: reference to 'size' is ambiguous
   58 |         size[x]+=size[t->y];
      |         ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:58:18: error: reference to 'size' is ambiguous
   58 |         size[x]+=size[t->y];
      |                  ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc: In function 'long long int sizes(long long int, long long int)':
a.cc:63:9: error: reference to 'size' is ambiguous
   63 |     if (size[x]>size[y]) swap(x,y);
      |         ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:63:17: error: reference to 'size' is ambiguous
   63 |     if (size[x]>size[y]) swap(x,y);
      |                 ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:64:16: error: reference to 'size' is ambiguous
   64 |     return min(size[x],size[0]-size[x]);
      |                ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:64:24: error: reference to 'size' is ambiguous
   64 |     return min(size[x],size[0]-size[x]);
      |                        ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:64:32: error: reference to 'size' is ambiguous
   64 |     return min(size[x],size[0]-size[x]);
      |                                ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc: In function 'bool size2(long long int, long long int)':
a.cc:68:9: error: reference to 'size' is ambiguous
   68 |     if (size[x]>size[y]) swap(x,y);
      |         ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:68:17: error: reference to 'size' is ambiguous
   68 |     if (size[x]>size[y]) swap(x,y);
      |                 ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:69:13: error: reference to 'size' is ambiguous
   69 |     return (size[x])==(size[0]-size[x]);
      |             ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:69:24: error: reference to 'size' is ambiguous
   69 |     return (size[x])==(size[0]-size[x]);
      |                        ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
a.cc:69:32: error: reference to 'size' is ambiguous
   69 |     return (size[x])==(size[0]-size[x]);
      |                                ^~~~
/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:47:5: note:                 'long long int size [100005]'
   47 | int size[100005];
      |     ^~~~
At global scope:
cc1plus: error: '::main' must return 'int'