Submission #550622

#TimeUsernameProblemLanguageResultExecution timeMemory
550622PherokungPower Plant (JOI20_power)C++14
100 / 100
200 ms28816 KiB
#include<bits/stdc++.h> using namespace std; #define N 200005 int n,u,v,dp[N],x[N],ans=0; char s[N]; vector<int> adj[N]; int sol(int u,int p){ int mx = 0; for(int v : adj[u]){ if(v == p) continue; dp[u] += sol(v,u); mx = max(mx,dp[v]); } dp[u] = max(dp[u]-x[u],x[u]); ans = max({ans,dp[u],mx+x[u]}); return dp[u]; } int main(){ scanf("%d",&n); for(int i=1;i<n;i++){ scanf("%d%d",&u,&v); adj[u].push_back(v), adj[v].push_back(u); } scanf("%s",s+1); for(int i=1;i<=n;i++) if(s[i] == '1') x[i] = 1; sol(1,1); printf("%d",ans); }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
power.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d%d",&u,&v);
      |   ~~~~~^~~~~~~~~~~~~~
power.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%s",s+1);
      |  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...