Submission #529590

#TimeUsernameProblemLanguageResultExecution timeMemory
529590MilosMilutinovicPower Plant (JOI20_power)C++14
100 / 100
183 ms28812 KiB
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i ++) #define rep1(i, n) for(int i = 1; i <= (int)(n); i ++) #define MP make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; int n, dp[200005], ans; vector<int> G[200005]; char s[200005]; void dfs(int v, int par) { rep(i, G[v].size()) { int u = G[v][i]; if(u == par) continue; dfs(u, v); if(s[v] == '1') ans = max(ans, dp[u] + 1); dp[v] += dp[u]; } dp[v] -= (s[v] == '1' ? 1 : 0); if(s[v] == '1') dp[v] = max(dp[v], 1); ans = max(ans, dp[v]); } int main() { scanf("%d", &n); rep(i, n - 1) { int a, b; scanf("%d%d", &a, &b); G[a].push_back(b); G[b].push_back(a); } scanf("%s", s + 1); dfs(1, 0); printf("%d", ans); return 0; }

Compilation message (stderr)

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