Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef __int128 INT;


int N;
int a[112345];
int b[112345];
INT c[112345];
INT s[112345];
int sub[112345];

typedef vector<int> V;
typedef vector<V> VV;

VV g;

INT abs(INT a){
    if(a<0)return -a;
    else return a;
}
INT tot ;
int tde = -1;
int cnt;
void dfs(int v,int p){
    sub[v]=1;
    for(auto &e:g[v]){
        int u = a[e]^b[e]^v;
        if(u==p)continue;
        dfs(u,v);
        sub[v]+=sub[u];
    }
    for(auto &e:g[v]){
        int u = a[e]^b[e]^v;
        if(u==p)continue;
        INT cnum = sub[u];
        INT vnum = N-sub[u];
        if(cnum!=vnum){
            c[e] = abs(s[v]-s[u]) / abs(cnum-vnum);
            tot -= c[e]*sub[u];
        }
        else {
            tde=e;
            cnt = sub[u];
        }
    }
}



int main(){
    cin>>N;
    g.resize(N);
    REP(i,N-1){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        g[a[i]].pb(i);
        g[b[i]].pb(i);
    }
    REP(i,N){
        LL x;
        cin>>x;
        s[i]=x;
    }
    tot = s[0];
    dfs(0,0);
    if(tde>=0)c[tde] = tot/cnt;
    REP(i,N-1){
        cout<<(LL)c[i]<<endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:71:23: error: call of overloaded 'abs(INT)' is ambiguous
   71 |             c[e] = abs(s[v]-s[u]) / abs(cnum-vnum);
      |                    ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:50:5: note: candidate: 'INT abs(INT)'
   50 | INT abs(INT a){
      |     ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:71:40: error: call of overloaded 'abs(INT)' is ambiguous
   71 |             c[e] = abs(s[v]-s[u]) / abs(cnum-vnum);
      |                                     ~~~^~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:50:5: note: candidate: 'INT abs(INT)'
   50 | INT abs(INT a){
      |     ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~