Submission #899024

#TimeUsernameProblemLanguageResultExecution timeMemory
899024penguin133Power Plant (JOI20_power)C++17
100 / 100
184 ms24192 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int dp[200005],ans; char A[200005]; vector<int>v[200005]; void dfs(int p, int x){ for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dfs(v[p][i], p); if(A[p] - '0'){ for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dp[p] += dp[v[p][i]], ans = max(ans, dp[v[p][i]] + 1); dp[p]--; dp[p] = max(1ll, dp[p]); } else for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dp[p] += dp[v[p][i]]; } main(){ int n;cin >> n; for(int i=1;i<n;i++){ int a,b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } for(int i=1;i<=n;i++)cin >> A[i]; dfs(1, -1); for(int i=1;i<=n;i++)ans = max(ans, dp[i]); cout << ans; }

Compilation message (stderr)

power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:9:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dfs(v[p][i], p);
      |              ~^~~~~~~~~~~~
power.cpp:11:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |   for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dp[p] += dp[v[p][i]], ans = max(ans, dp[v[p][i]] + 1);
      |               ~^~~~~~~~~~~~
power.cpp:15:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  else for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dp[p] += dp[v[p][i]];
      |                   ~^~~~~~~~~~~~
power.cpp: At global scope:
power.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...