Submission #766080

# Submission time Handle Problem Language Result Execution time Memory
766080 2023-06-25T09:53:37 Z yusuf12360 Power Plant (JOI20_power) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
int ans=1;
vector<int> res;
vector<vector<int>> adj;
string s;
void dfs1(int u=0, int p=-1) {
	res[u]=s[u]-'0';
	for(int pp : adj[u]) {
		if(pp==p) continue;
		dfs1(pp, u);
		if(s[pp]=='1') res[u]++;
		else res[u]+=res[pp];
	}
}
void dfs2(int u=0, int p=-1, int to_p=0) {
	int tot=0, mx=0, path=0;
	if(to_p>0) tot+=to_p, mx=max(mx, to_p), path++;
	for(int pp : adj[u]) {
		if(pp==p) continue;
		if(res[pp]>0) tot+=res[pp], mx=max(mx, res[pp]), path++;
		if(s[u]=='1') dfs2(pp, u, 1);
		else dfs2(pp, u, to_p+res[u]-(s[pp]=='1' ? 1 : res[pp]));
	}
	if(path==1) ans=max(ans, tot+(s[i]=='1'));
	else ans=max({ans, tot-(s[i]=='1'), mx+1});
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	res.resize(n); adj.resize(n);
	while(--n) {
		int u, v; cin >> u >> v; --u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);}
	cin >> s;
	dfs1();
	dfs2();
	cout << ans << '\n';
	return 0;
}

Compilation message

power.cpp: In function 'void dfs2(int, int, int)':
power.cpp:25:34: error: 'i' was not declared in this scope
   25 |  if(path==1) ans=max(ans, tot+(s[i]=='1'));
      |                                  ^
power.cpp:26:28: error: 'i' was not declared in this scope
   26 |  else ans=max({ans, tot-(s[i]=='1'), mx+1});
      |                            ^
power.cpp:26:43: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   26 |  else ans=max({ans, tot-(s[i]=='1'), mx+1});
      |                                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from power.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
power.cpp:26:43: note:   candidate expects 2 arguments, 1 provided
   26 |  else ans=max({ans, tot-(s[i]=='1'), mx+1});
      |                                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from power.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
power.cpp:26:43: note:   candidate expects 3 arguments, 1 provided
   26 |  else ans=max({ans, tot-(s[i]=='1'), mx+1});
      |                                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from power.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed: