Submission #793146

#TimeUsernameProblemLanguageResultExecution timeMemory
793146antonPower Plant (JOI20_power)C++17
0 / 100
3 ms4948 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int MAX_N = 2*1e5; int n, dp[MAX_N][2]; string s; vector<int> adj[MAX_N]; void dfs(int id, int anc){ for(int i = 0; i<adj[id].size(); i++){ if(adj[id][i] == anc){ adj[id].erase(adj[id].begin() +i); break; } } for(auto e: adj[id]){ dfs(e, id); } } void find_dp(int id){ dp[id][0]= 0; dp[id][1] = 0; bool gen = s[id] == '1'; int s1=0; int best1= 0; int best0= 0; for(auto e: adj[id]){ find_dp(e); s1 += dp[e][1]; best1 = max(best1, dp[e][1]); best0 = max(best0, dp[e][0]); } if(!gen){ dp[id][0] = max(max(s1, best0), 0LL); dp[id][1] = max(s1, 0LL); } else{ dp[id][0] = max(s1-1, best1+1); dp[id][1] = max(s1-1, 1LL); } //cout<<id<<" "<<dp[id][0]<<" "<<dp[id][1]<<endl; } signed main(){ cin>>n; for(int i = 0; i<n-1; i++){ int a, b; cin>>a>>b; a--;b--; adj[a].push_back(b); adj[b].push_back(a); } dfs(0, -1); cin>>s; find_dp(0); cout<<dp[0][0]<<endl; }

Compilation message (stderr)

power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:12:21: 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]
   12 |     for(int i = 0; i<adj[id].size(); i++){
      |                    ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...