Submission #516483

#TimeUsernameProblemLanguageResultExecution timeMemory
516483leinad2Power Plant (JOI20_power)C++17
100 / 100
171 ms29644 KiB
#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, a, b, A[200010], dp[200010], ans;
vector<int>adj[200010];
char S[200010];
void dfs(int v, int par)
{
    int a=0, b=0;
    for(auto p:adj[v])
    {
        if(p==par)continue;
        dfs(p, v);
        a+=dp[p];
        b=max(b, dp[p]);
    }
    dp[v]=max(a-A[v], A[v]);
    ans=max(ans, b+A[v]);
    ans=max(ans, dp[v]);
}
main()
{
    scanf("%d", &n);
    for(i=0;++i<n;)
    {
        scanf("%d %d", &a, &b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    scanf("%s", &S);
    for(i=0;i++<n;)A[i]=S[i-1]-'0';
    dfs(1, 0);
    cout<<ans;
}

Compilation message (stderr)

power.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main()
      | ^~~~
power.cpp: In function 'int main()':
power.cpp:29:13: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[200010]' [-Wformat=]
   29 |     scanf("%s", &S);
      |            ~^   ~~
      |             |   |
      |             |   char (*)[200010]
      |             char*
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:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
power.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%s", &S);
      |     ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...