Submission #534696

# Submission time Handle Problem Language Result Execution time Memory
534696 2022-03-08T14:40:25 Z michao Power Plant (JOI20_power) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
//#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e5+5;
vi P[MAX];
int c[MAX];
int dp[MAX];
char s[MAX];
int ans=0;

void dfs(int u,int fa){
	vi d;
	d.clear();
	vi wrzut;
	int maxi=0;
	for (auto it:P[u]){
		if (it==fa)continue;
		dfs(it,u);
		d.pb(it);
		maxi=max(maxi,dp[it]);
	}
	
	if (c[u]==0){
		for (auto v:d)dp[u]+=dp[v];
		ans=max(ans,dp[u]);
	}
	else{
		assert(c[u]==1);
		int sum=0;
		for (auto v:d)sum+=dp[v];
		if (sum==0)dp[u]=1,ans=max(ans,dp[u]);
		else{
			dp[u]=max(1LL,sum-1);
			ans=max(ans,maxi+1);
			ans=max(ans,dp[u]);
		}
	}
}
int32_t main(){
  BOOST;
  int n;
  cin>>n;
  for (int i=1;i<=n-1;i++){
		int a,b;
		cin>>a>>b;
		P[a].pb(b);
		P[b].pb(a);
  }
  for (int i=1;i<=n;i++){
		cin>>s[i];
		c[i]=s[i]-'0';
  }
  dfs(1,-1);
  for (int i=1;i<=n;i++)cerr<<"DPEK "<<i<<" "<<dp[i]<<"\n";
  cout<<ans;
  return 0; 
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:45:23: error: no matching function for call to 'max(long long int, int)'
   45 |    dp[u]=max(1LL,sum-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:45:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   45 |    dp[u]=max(1LL,sum-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:45:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   45 |    dp[u]=max(1LL,sum-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:
power.cpp:45:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   45 |    dp[u]=max(1LL,sum-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: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:
power.cpp:45:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   45 |    dp[u]=max(1LL,sum-1);
      |                       ^