Submission #295456

#TimeUsernameProblemLanguageResultExecution timeMemory
295456dsabolicPower Plant (JOI20_power)C++17
0 / 100
5 ms5076 KiB
#include <bits/stdc++.h> #define rep(i, a, n) for(int (i) = (a); (i) < (n); ++(i)) using namespace std; const int N = 2e5 + 50; int n; vector<int> graph[N]; string s; int dp[N]; int sol = 0; int rek(int v, int p) { int sum = 0, mx = 0, cnt = 0; for(auto n : graph[v]) { if(n == p) continue; int val = rek(n, v); if(val) cnt++; sum += val; mx = max(mx, val); } if(s[v] == '0' || cnt > 1) dp[v] = max(s[v] - '0', sum - s[v] + '0'); else dp[v] = max(1, sum); if(s[v] == '1') { sol = max(sol, max(mx + 1, dp[v])); } else { sol = max(sol, dp[v]); } return dp[v]; } int main() { cin >> n; rep(i, 0, n - 1) { int a, b; cin >> a >> b; --a, --b; graph[a].push_back(b); graph[b].push_back(a); } cin >> s; rek(0, -1); printf("%d\n", sol); return 0; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:3:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define rep(i, a, n) for(int (i) = (a); (i) < (n); ++(i))
      |                              ^
power.cpp:40:9: note: in expansion of macro 'rep'
   40 |         rep(i, 0, n - 1) {
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...