Language: C++

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

struct Edge {
    int u, v, w;
};

const int N = 1e5 + 5;

ll p[N], sum[N], mx[N], kek[N];
int bad;

int getRoot(int v) {
    return v == p[v] ? v : p[v] = getRoot(p[v]);
}

void unite(int v, int u, int weight) {
    v = getRoot(v), u = getRoot(u);
    if (v == u) {
        mx[v] = max(mx[v], weight);
        if (weight > sum[v]) {
            kek[v]++;
            bad++;
        }
        return;
    }
    p[u] = v;
    sum[v] += sum[u];
    mx[v] = max({ mx[v], mx[u], weight });
    bad -= kek[v] + kek[u];
    if (mx[v] > sum[v]) {
        kek[v] += kek[u] + 1;
    } else {
        kek[v] = 0;
    }
    bad += kek[v];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    iota(p, p + n, 0);
    for (int i = 0; i < n; i++) {
        cin >> sum[i];
    }
    vector<Edge> edges(m);
    for (int i = 0; i < m; i++) {
        cin >> edges[i].u >> edges[i].v >> edges[i].w;
        edges[i].u--;
        edges[i].v--;
    }
    sort(edges.begin(), edges.end(), [](auto& a, auto& b) {
        return a.w < b.w;
    });
    
    for (auto edge : edges) {
        unite(edge.u, edge.v, edge.w);
    }

    cout << bad << endl;
    return 0;
}

Compiler output:
a.cc: In function 'void unite(int, int, int)':
a.cc:23:20: error: no matching function for call to 'max(ll&, int&)'
   23 |         mx[v] = max(mx[v], weight);
      |                 ~~~^~~~~~~~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:23:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   23 |         mx[v] = max(mx[v], weight);
      |                 ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:23:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   23 |         mx[v] = max(mx[v], weight);
      |                 ~~~^~~~~~~~~~~~~~~
a.cc:32:16: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   32 |     mx[v] = max({ mx[v], mx[u], weight });
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
a.cc:32:16: note:   deduced conflicting types for parameter '_Tp' ('long long int' and 'int')
   32 |     mx[v] = max({ mx[v], mx[u], weight });
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided