Submission #301024

#TimeUsernameProblemLanguageResultExecution timeMemory
301024milisavPower Plant (JOI20_power)C++14
100 / 100
249 ms68344 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") #define maxn 2000000 using namespace std; int n; vector<int> a[maxn]; char s[maxn]; int dp[maxn]; int ans=0; void dfs(int u,int p=-1) { for(auto v:a[u]) if(v!=p) dfs(v,u); int ad=0; if(s[u]=='1') ad=1; for(auto v:a[u]) if(v!=p) ans=max(ans,dp[v]+ad); dp[u]=-ad; for(auto v:a[u]) if(v!=p) dp[u]+=dp[v]; dp[u]=max(dp[u],ad); ans=max(ans,dp[u]); } int main() { int u,v; scanf("%d",&n); for(int i=0;i<n-1;i++) { scanf("%d %d",&u,&v); a[u].push_back(v); a[v].push_back(u); } scanf("%s",s+1); dfs(1); printf("%d",ans); return 0; }

Compilation message (stderr)

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