Submission #550550

#TimeUsernameProblemLanguageResultExecution timeMemory
550550krit3379Power Plant (JOI20_power)C++17
100 / 100
196 ms29516 KiB
#include<bits/stdc++.h> using namespace std; #define N 200005 int dp[N],p[N],ans; char s[N]; vector<int> g[N]; void dfs(int s,int f){ int ma=0; for(auto x:g[s]){ if(x==f)continue; dfs(x,s); dp[s]+=dp[x]; ma=max(ma,dp[x]); } dp[s]-=p[s]; dp[s]=max(dp[s],p[s]); ans=max({ans,ma+p[s],dp[s]}); } int main(){ int n,i,a,b; scanf("%d",&n); for(i=1;i<n;i++){ scanf("%d %d",&a,&b); g[a].push_back(b); g[b].push_back(a); } scanf(" %s",s+1); for(i=1;i<=n;i++)p[i]=s[i]-'0'; dfs(1,0); printf("%d",ans); return 0; }

Compilation message (stderr)

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