Language: C++

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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int DIRECTED = 0;
const int UNDIRECTED = 1;

template<int isUNDIRECTED=0>
class Graph{
protected:
	struct Edge{
		int u, v, id; // from, to, 何番目の辺か
		ll c; // cost
		Edge(int u, int v, ll c=0, int id=0):u(u), v(v), c(c), id(id){}
	};

	int V, E; // 頂点数、辺数
	vector<vector<Edge>> G;
	vector<Edge> Es;

public:
	Graph(){}
	Graph(int V):V(V){G.resize(V);}
	Graph(const Graph<isUNDIRECTED>& g):V(g.V), E(g.E), G(g.G), Es(g.Es){}

	void add_edge(int u, int v, ll c=0, int id=0){
		G[u].emplace_back(u, v, c, id);
		if(isUNDIRECTED) G[v].emplace_back(v, u, c, id);
		Es.emplace_back(u, v, c, id);
		E++;
	}

	const vector<Edge>& operator[](int k){
		return G[k];
	}

	unsigned long long size(){
		return V;
	}
};

template<int isUNDIRECTED>
class Lowlink : public Graph<isUNDIRECTED>{
	vector<int> ord, low;
	vector<int> articulation;
	vector<pair<int, int>> bridge;
public:
	Lowlink(){}
	Lowlink(int V):Graph<isUNDIRECTED>(V){}
	Lowlink(const Graph<isUNDIRECTED>& g):Graph<isUNDIRECTED>(g){}

	void build(){
		ord.resize(this->V, -1);
		low.resize(this->V, -1);
		int k = 0;
		
		function<void(int, int)> dfs = [&, this](int v, int p){
			ord[v] = k++;
			low[v] = ord[v];
			bool isArt = 0; // 関節点か
			int cnt = 0;

			for(auto e : this->G[v]){
				if(e.v == p) continue;
				if(ord[e.v] == -1){
					cnt++;
					dfs(e.v, v);
					low[v] = min(low[v], low[e.v]);
					if(ord[v] < low[e.v]) bridge.emplace_back(e.u, e.v);
					if(~p && ord[v] <= low[e.v]) isArt = 1;
				}else{
					low[v] = min(low[v], ord[e.v]);
				}
			}
			if(p==-1 && cnt > 1) isArt = 1;
			if(isArt) articulation.push_back(v);
		};
		for(int i = 0;i < this->V;i++)
			if(ord[i] == -1) dfs(i, -1);
	}

	const vector<pair<int, int>>& getBridge(){
		return bridge;
	}
	
	const vector<int>& getArticulation(){
		return articulation;
	}

	bool isBridge(int u, int v) const{
		if(ord[u] > ord[v]) swap(u, v);
		return ord[u] < low[v];
	}
};

template<int isUNDIRECTED>
class BECC{
private:
	Lowlink<isUNDIRECTED> orgG;
	Graph<isUNDIRECTED> G;
	vector<int> belongs;
	vector<vector<int>> comps;

public:
	BECC(){}
	BECC(const Graph<isUNDIRECTED>& g):orgG(g){
		orgG.build();
		belongs.resize(orgG.size(), -1);
	}

	void build(){
		vector<bool> used(orgG.size(), 0);
		int k = 0;
		function<void(int, int)> dfs = [&](int v, int p){
			belongs[v] = k;
			if(p == -1)
				comps.push_back(vector<int>());
			comps[k].push_back(v);
			for(auto e : orgG[v]){
				if(e.v == p) continue;
				if(orgG.isBridge(e.u, e.v)) continue;
				if(belongs[e.v] >= 0) continue;

				dfs(e.v, v);
			}
		};

		for(int i = 0;i < orgG.size();i++){
			if(belongs[i] >= 0) continue;
			dfs(i, -1);
			k++;
		}

		G = Graph<isUNDIRECTED>(k);
		for(auto e : orgG.getBridge()){
			G.add_edge(belongs[e.first], belongs[e.second]);
		}
	}

	int belong(int v){
		return belongs[v]; }

	int size(int v){
		return comps[v].size();
	}
	
	const Graph<isUNDIRECTED>& getGraph(){
		return G;
	}
};

int N, M;
Graph<UNDIRECTED> orgG;
Graph<UNDIRECTED> tree;

int main(void){
	cin >> N >> M;
	orgG = Graph<UNDIRECTED>(N);
	REP(i, M){
		int s, t;
		cin >> s >> t;
		orgG.add_edge(s, t);
	}
	BECC<UNDIRECTED> becc(orgG);
	becc.build();
	tree = becc.getGraph();
	vector<vector<int>> dp(tree.size(), vector<int>(2, 0));

	function<void(int, int)> dfs = [&](int v, int p){
		int sum[2] = {};
		for(auto e : tree[v]){
			if(e.v == p) continue;
			dfs(e.v, v);
			sum[0] += max(dp[e.v][0], dp[e.v][1]);
			sum[1] += dp[e.v][0];
		}

		dp[v][0] = sum[0];
		dp[v][1] = sum[1]+becc.size(v);
	};
	int res = 0;
	REP(i, tree.size()){
		if(dp[i] == 0)
			dfs(i, -1);
	}
	cout << max(dp[0][0], dp[0][1]) << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:198:26: error: no match for 'operator==' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and 'int')
  198 |                 if(dp[i] == 0)
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181,
                 from a.cc:1:
/usr/include/c++/14/bits/regex.h:1103:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1103 |     operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1103:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/regex.h:1199:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1199 |     operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1199:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/regex.h:1274:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1274 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1274:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/regex.h:1366:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1366 |     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1366:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/regex.h:1441:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1441 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1441:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/regex.h:1534:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
 1534 |     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1534:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/regex.h:1613:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1613 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1613:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/regex.h:2186:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator==(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)'
 2186 |     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:2186:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>'
  198 |                 if(dp[i] == 0)
      |                             ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1033:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1033 |     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1033:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::pair<_T1, _T2>'
  198 |                 if(dp[i] == 0)
      |                             ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:441:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  441 |     operator==(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:441:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/stl_iterator.h:486:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  486 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:486:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1667 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::move_iterator<_IteratorL>'
  198 |                 if(dp[i] == 0)
      |                             ^
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1737 |     operator==(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::move_iterator<_IteratorL>'
  198 |                 if(dp[i] == 0)
      |                             ^
In file included from /usr/include/c++/14/bits/char_traits.h:42,
                 from /usr/include/c++/14/string:42,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/postypes.h:192:5: note: candidate: 'template<class _StateT> bool std::operator==(const fpos<_StateT>&, const fpos<_StateT>&)'
  192 |     operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/postypes.h:192:5: note:   template argument deduction/substitution failed:
a.cc:198:29: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::fpos<_StateT>'
  198 |                 if(dp[i] == 0)
      |                             ^
In file included from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/allocator.h:235:5: note: candidate: 'template<class _T1, class _T2> bool std::operator==(const