Language: C++

#include<bits/stdc++.h>

using namespace std;

struct Edge{
    int src,dst;
    Edge(int src,int dst):
    src(src),dst(dst){}
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;

int memo[100001];

pair<vector<int>, Edges> bridge(const Graph& g) {
	const int n = g.size();
	int idx = 0, s = 0, t = 0, k = 0;
	vector<int>ord(n, -1), onS(n), stk(n), roots(n), cmp(n);
	Edges brdg;
	function<void(int, int)> dfs = [&](int v, int u) {
		ord[v] = idx++;
		stk[s++] = v;
		onS[v] = true;
		roots[t++] = v;
		for (auto& e : g[v]) {
			int w = e.dst;
			if (ord[w] == -1)dfs(w, v);
			else if (u != w && onS[w])
				while (ord[roots[t - 1]]>ord[w])--t;
		}
		if (v == roots[t - 1]) {
			brdg.emplace_back(u, v);
			while (true) {
				int w = stk[--s];
				onS[w] = false;
				cmp[w] = k;
				if (v == w)break;
			}
			--t;
			++k;
		}
	};
	for (int u = 0; u<n; ++u) {
		if (ord[u] == -1) {
			dfs(u, n);
			brdg.pop_back();
		}
	}
	return make_pair(cmp, brdg);
}

bool dfs0(const Graph &g,int p,int v,vector<bool> &elect,
vector<int>&elements,vector<int>&cycle){
    for(auto e:g[v]){
        if(e.dst==p)continue;
        if(elements[cycle[e.dst]]>1 || elect[e.dst])return elect[v]=1;
        if(dfs0(g,v,e.dst,elect,elements,cycle))return elect[v]=1;
    }
    return 0;
}

int dfs1(const Graph &g,int p,int v,vector<bool> &elect,
vector<int>&elements,vector<int>&cycle,vector<Weight>&node){
    if(memo[v])return memo[v];
    int res=0;
    for(auto e:g[v]){
        if(elect[e.dst]){
            return memo[v]=node[v];
        }
        if(e.dst!=p && elements[cycle[e.dst]]==1){
            res=dfs1(g,v,e.dst,elect,elements,cycle,node);
            if(res){
                return memo[v]=res+node[v];
            }
        }
    }
    return 0;
}

int main(){
    int n,m;
    cin>>n>>m;
    Graph g(n);
    vector<Weight>node(n);
    for(int i=0;i<n;++i){
        cin>>node[i];
    }
    for(int i=0;i<m;++i){
        int s,t;
        cin>>s>>t;
        --s;--t;
        g[s].emplace_back(s,t);
        g[t].emplace_back(t,s);
    }
    vector<int>cycle = bridge(g).first;
    vector<int>elements(n,0);
    for(int i=0;i<n;++i){
        elements[cycle[i]]++;
    }
    vector<bool>elect(n,false);
    elect[0]=true;
    for(int i=1;i<n;++i){
        if(elements[cycle[i]]>1){
            dfs0(g,-1,i,elect,elements,cycle);
        }
    }
    int buf=0;
    for(int i=1;i<n;++i){
        if(g[i].size()==1){
            buf=max(buf,dfs1(g,-1,g[i][0].src,elect,elements,cycle,node));
        }
    }
    int ans=0;
    for(int i=0;i<n;++i){
        if(elect[i]){
            ans+=node[i];
        }
    }
    ans+=buf;
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc:64:47: error: 'Weight' was not declared in this scope
   64 | vector<int>&elements,vector<int>&cycle,vector<Weight>&node){
      |                                               ^~~~~~
a.cc:64:53: error: template argument 1 is invalid
   64 | vector<int>&elements,vector<int>&cycle,vector<Weight>&node){
      |                                                     ^
a.cc:64:53: error: template argument 2 is invalid
a.cc: In function 'int dfs1(const Graph&, int, int, std::vector<bool>&, std::vector<int>&, std::vector<int>&, int&)':
a.cc:69:32: error: invalid types 'int[int]' for array subscript
   69 |             return memo[v]=node[v];
      |                                ^
a.cc:74:40: error: invalid types 'int[int]' for array subscript
   74 |                 return memo[v]=res+node[v];
      |                                        ^
a.cc: In function 'int main()':
a.cc:85:12: error: 'Weight' was not declared in this scope
   85 |     vector<Weight>node(n);
      |            ^~~~~~
a.cc:85:18: error: template argument 1 is invalid
   85 |     vector<Weight>node(n);
      |                  ^
a.cc:85:18: error: template argument 2 is invalid
a.cc:87:18: error: invalid types 'int[int]' for array subscript
   87 |         cin>>node[i];
      |                  ^
a.cc:117:22: error: invalid types 'int[int]' for array subscript
  117 |             ans+=node[i];
      |                      ^