Language: C++

#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
using pii = pair<ll, ll>;

struct Graph {
    Graph(const ll n)
    {
        edge.resize(n);
        revedge.resize(n);
    }
    void addEdge(const ll from, const ll to)
    {
        edge[from].push_back(to);
        revedge[to].push_back(from);
    }
    vector<vector<ll>> edge;
    vector<vector<ll>> revedge;
};

void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
{
    depth[s] = deg;
    for (const ll to : g.edge[s]) {
        if (not used[to]) {
            used[to] = true;
            dig.addEdge(s, to);
            diedge[make_pair(s, to)] = 0;
            resedge.erase(make_pair(s, to));
            resedge.erase(make_pair(to, s));
            depth_dfs(g, dig, diedge, resedge, to, depth, used, deg + 1);
        }
    }
}

void accum(const Graph& dig, const ll s, map<pii, ll>& diedge)
{
    for (const ll to : dig.edge[s]) {
        ll sum = 0;
        accum(dig, to, diedge);
        for (const ll to2 : dig.edge[to]) {
            sum += diedge[make_pair(to, to2)];
        }
        diedge[make_pair(s, to)] += sum;
    }
}

void cc_dfs(const Graph& newg, const ll s, vector<ll>& comp, vector<bool>& visited, const ll cnum)
{
    visited[s] = true;
    comp[s] = cnum;
    for (const ll to : newg.edge[s]) {
        cc_dfs(newg, to, comp, visited, cnum);
    }
}

void decomp(const Graph& dig, Graph& decomped, const ll s, const vector<ll>& comp, set<pii>& decomped_edge)
{
    const ll c1 = comp[s];
    for (const ll to : dig.edge[s]) {
        decomp(dig, decomped, to, comp, decomped_edge);
        const ll c2 = comp[to];
        if (c1 != c2 and decomped_edge.find(make_pair(c1, c2)) == decomped_edge.end()) {
            decomped_edge.insert(make_pair(c1, c2));
            decomped.addEdge(c1, c2);
        }
    }
}

ll weight_dfs(const Graph& decomped, const ll s, const vector<ll>& weight)
{
    ll maxi = 0;
    for (const ll to : decomped.edge[s]) {
        maxi = max(maxi, weight_dfs(decomped, to, weight));
    }
    return weight[s] + maxi;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    Graph g(N);
    vector<ll> w(N);
    for (ll i = 0; i < N; i++) {
        cin >> w[i];
    }
    map<pii, ll> edges;
    for (ll i = 0; i < M; i++) {
        ll u, v;
        cin >> u >> v;
        u--, v--;
        g.addEdge(u, v);
        g.addEdge(v, u);
        edges[make_pair(u, v)] = 0;
        edges[make_pair(v, u)] = 0;
    }
    Graph dig(N);
    map<pii, ll> diedge;
    map<pii, ll> resedge = edges;
    vector<ll> depth(N, 0);
    vector<bool> used(N, false);
    used[0] = true;
    depth_dfs(g, dig, diedge, resedge, 0, depth, used, 0);
    map<pii, ll> resedge_ = resedge;
    resedge.clear();
    for (const auto& e : resedge_) {
        const ll u = e.first.first;
        const ll v = e.first.second;
        if (resedge.find(make_pair(v, u)) == resedge.end()) {
            resedge[make_pair(u, v)] = 0;
        }
    }
    for (const auto& e : resedge) {
        const ll u = e.first.first;
        const ll v = e.first.second;
        ll a;
        ll b;
        if (depth[u] < depth[v]) {
            b = u;
            a = v;
        } else {
            b = v;
            a = u;
        }
        if (not dig.revedge[b].empty()) {
            const ll par = dig.revedge[b][0];
            diedge[make_pair(par, b)]--;
        }
        const ll par = dig.revedge[a][0];
        diedge[make_pair(par, a)]++;
    }
    vector<ll> node(N, 0);
    accum(dig, 0, diedge);
    Graph newg(N);
    for (const auto& e : diedge) {
        if (e.second != 0) {
            const ll u = e.first.first;
            const ll v = e.first.second;
            newg.addEdge(u, v);
        }
    }
    vector<bool> visited(N, false);
    vector<ll> comp(N, 0);
    ll cnum = 0;
    for (ll i = 0; i < N; i++) {
        if (not visited[i]) {
            cc_dfs(newg, i, comp, visited, cnum);
            cnum++;
        }
    }
    vector<ll> weight(cnum, 0);
    for (ll i = 0; i < N; i++) {
        const ll c = comp[i];
        weight[c] += w[i];
    }
    set<pii> decomped_edge;
    Graph decomped(cnum);
    decomp(dig, decomped, 0, comp, decomped_edge);

    cout << weight_dfs(decomped, 0, weight) << endl;

    return 0;
}

Compiler output:
a.cc:6:18: error: 'll' was not declared in this scope
    6 | using pii = pair<ll, ll>;
      |                  ^~
a.cc:6:22: error: 'll' was not declared in this scope
    6 | using pii = pair<ll, ll>;
      |                      ^~
a.cc:6:24: error: template argument 1 is invalid
    6 | using pii = pair<ll, ll>;
      |                        ^
a.cc:6:24: error: template argument 2 is invalid
a.cc:9:17: error: 'll' does not name a type
    9 |     Graph(const ll n)
      |                 ^~
a.cc:14:24: error: 'll' does not name a type
   14 |     void addEdge(const ll from, const ll to)
      |                        ^~
a.cc:14:39: error: 'll' does not name a type
   14 |     void addEdge(const ll from, const ll to)
      |                                       ^~
a.cc:19:19: error: 'll' was not declared in this scope
   19 |     vector<vector<ll>> edge;
      |                   ^~
a.cc:19:19: error: template argument 1 is invalid
a.cc:19:19: error: template argument 2 is invalid
a.cc:19:21: error: template argument 1 is invalid
   19 |     vector<vector<ll>> edge;
      |                     ^~
a.cc:19:21: error: template argument 2 is invalid
a.cc:20:19: error: 'll' was not declared in this scope
   20 |     vector<vector<ll>> revedge;
      |                   ^~
a.cc:20:19: error: template argument 1 is invalid
a.cc:20:19: error: template argument 2 is invalid
a.cc:20:21: error: template argument 1 is invalid
   20 |     vector<vector<ll>> revedge;
      |                     ^~
a.cc:20:21: error: template argument 2 is invalid
a.cc: In constructor 'Graph::Graph(int)':
a.cc:11:14: error: request for member 'resize' in '((Graph*)this)->Graph::edge', which is of non-class type 'int'
   11 |         edge.resize(n);
      |              ^~~~~~
a.cc:12:17: error: request for member 'resize' in '((Graph*)this)->Graph::revedge', which is of non-class type 'int'
   12 |         revedge.resize(n);
      |                 ^~~~~~
a.cc: In member function 'void Graph::addEdge(int, int)':
a.cc:16:13: error: invalid types 'int[const int]' for array subscript
   16 |         edge[from].push_back(to);
      |             ^
a.cc:17:16: error: invalid types 'int[const int]' for array subscript
   17 |         revedge[to].push_back(from);
      |                ^
a.cc: At global scope:
a.cc:23:48: error: 'pii' was not declared in this scope
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                ^~~
a.cc:23:53: error: 'll' was not declared in this scope
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                     ^~
a.cc:23:55: error: template argument 1 is invalid
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                       ^
a.cc:23:55: error: template argument 2 is invalid
a.cc:23:55: error: template argument 3 is invalid
a.cc:23:55: error: template argument 4 is invalid
a.cc:23:70: error: 'pii' was not declared in this scope
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                                      ^~~
a.cc:23:75: error: 'll' was not declared in this scope
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                                           ^~
a.cc:23:77: error: template argument 1 is invalid
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                                             ^
a.cc:23:77: error: template argument 2 is invalid
a.cc:23:77: error: template argument 3 is invalid
a.cc:23:77: error: template argument 4 is invalid
a.cc:23:95: error: 'll' does not name a type
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                                                               ^~
a.cc:23:108: error: 'll' was not declared in this scope
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                                                                            ^~
a.cc:23:110: error: template argument 1 is invalid
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                                                                              ^
a.cc:23:110: error: template argument 2 is invalid
a.cc:23:146: error: 'll' does not name a type
   23 | void depth_dfs(const Graph& g, Graph& dig, map<pii, ll>& diedge, map<pii, ll>& resedge, const ll s, vector<ll>& depth, vector<bool>& used, const ll deg)
      |                                                                                                                                                  ^~
a.cc: In function 'void depth_dfs(const Graph&, Graph&, int&, int&, int, int&, std::vector<bool>&, int)':
a.cc:25:10: error: invalid types 'int[const int]' for array subscript
   25 |     depth[s] = deg;
      |          ^
a.cc:26:16: error: 'll' does not name a type
   26 |     for (const ll to : g.edge[s]) {
      |                ^~
a.cc:35:6: error: expected ';' before '}' token
   35 |     }
      |      ^
      |      ;
   36 | }
      | ~     
a.cc:36:1: error: expected primary-expression before '}' token
   36 | }
      | ^
a.cc:35:6: error: expected ';' before '}' token
   35 |     }
      |      ^
      |      ;
   36 | }
      | ~     
a.cc:36:1: error: expected primary-expression before '}' token
   36 | }
      | ^
a.cc:35:6: error: expected ')' before '}' token
   35 |     }
      |      ^
      |      )
   36 | }
      | ~     
a.cc:26:9: note: to match this '('
   26 |     for (const ll to : g.edge[s]) {
      |         ^
a.cc:36:1: error: expected primary-expression before '}' token
   36 | }
      | ^
a.cc: At global scope:
a.cc:38:36: error: 'll' does not name a type
   38 | void accum(const Graph& dig, const ll s, map<pii, ll>& diedge)
      |                                    ^~
a.cc:38:46: error: 'pii' was not declared in this scope
   38 | void accum(const Graph& dig, const ll s, map<pii, ll>& diedge)
      |                                              ^~~
a.cc:38:51: error: 'll' was not declared in this scope
   38 | void accum(const Graph& dig, const ll s, map<pii, ll>& diedge)
      |                                                   ^~
a.cc:38:53: error: template argument 1 is invalid
   38 | void accum(const Graph& dig, const ll s, map<pii, ll>& diedge)
      |                                                     ^
a.cc:38:53: error: template argument 2 is invalid
a.cc:38:53: error: template argument 3 is invalid
a.cc:38:53: error: template argument 4 is invalid
a.cc: In function 'void accum(const Graph&, int, int&)':
a.cc:40:16: error: 'll' does not name a type
   40 |     for (const ll to : dig.edge[s]) {
      |                ^~
a.cc:47:6: error: expected ';' before '}' token
   47 |     }
      |      ^
      |      ;
   48 | }
      | ~     
a.cc:48:1: error: expected primary-expression before '}' token
   48 | }
      | ^
a.cc:47:6: error: expected ';' before '}' token
   47 |     }
      |      ^
      |      ;
   48 | }
      | ~     
a.cc:48:1: error: expected primary-expression before '}' token
   48 | }
      | ^
a.cc:47:6: error: expected ')' before '}' token
   47 |     }
      |      ^
      |      )
   48 | }
      | ~     
a.cc:40:9: note: to match this '('
   40 |     for (const ll to : dig.edge[s]) {
      |         ^
a.cc:48:1: error: expected primary-expression before '}' token
   48 | }
      | ^
a.cc: At global scope:
a.cc:50:38: error: 'll' does not name a type
   50 | void cc_dfs(const Graph& newg, const ll s, vector<ll>& comp, vector<bool>& visited, const ll cnum)
      |                                      ^~
a.cc:50:51: error: 'll' was not declared in this scope
   50 | void cc_dfs(const Graph& newg, const ll s, vector<ll>& comp, vector<bool>& visited, const ll cnum)
      |                                                   ^~
a.cc:50:53: error: template argument 1 is invalid
   50 | void cc_dfs(const Graph& newg, const ll s, vector<ll>& comp, vector<bool>& visited, const ll cnum)
      |                                                     ^
a.cc:50:53: error: template argument 2 is invalid
a.cc:50:91: error: 'll' does not name a type
   50 | void cc_dfs(const Graph& newg, const ll s, vector<ll>& comp, vector<bool>& visited, const ll cnum)
      |                                                                                           ^~
a.cc: In function 'void cc_dfs(const Graph&, int, int&, std::vector<bool>&, int)':
a.cc:53:9: error: invalid types 'int[const int]' for array subscript
   53 |     comp[s] = cnum;
      |         ^
a.cc:54:16: error: 'll' does not name a type
   54 |     for (const ll to : newg.edge[s]) {
      |                ^~
a.cc:56:6: error: expected ';' before '}' token
   56 |     }
      |      ^
      |      ;
   57 | }
      | ~     
a.cc:57:1: error: expected primary-expression before '}' token
   57 | }
      | ^
a.cc:56:6: error: expected ';' before '}' token
   56 |     }
      |      ^
      |      ;
   57 | }
      | ~     
a.cc:57:1: error: expected primary-expression before '}' token
   57 | }
      | ^
a.cc:56:6: error: expect