Submission #307500

# Submission time Handle Problem Language Result Execution time Memory
307500 2020-09-28T11:35:11 Z asifthegreat Power Plant (JOI20_power) C++17
100 / 100
412 ms 30856 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5;

vector<int>graph[N];
int dp[N];
string s = ":";
int res = 0;

void dfs(int v, int par){
    int mx = 0;
    for(auto c : graph[v]){
        if(c == par) continue;
        dfs(c, v);
        dp[v] += dp[c];
        mx = max(mx, dp[c]);
    }
    if(s[v] == '1') res = max(res, 1+mx);
    else res = max(res, dp[v]);
    dp[v] -= s[v]-'0';
    if(dp[v] <= 0 && s[v] == '1') dp[v] = 1;
    res = max(res, dp[v]);
}
int main(){

  int n;
  cin >> n;
  for(int i = 1; i < n;i++){
    int a,b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  string t;
  cin >> t;
  s+=t;
  dfs(1, 0);
  cout << res << endl;

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7296 KB Output is correct
4 Correct 5 ms 7296 KB Output is correct
5 Correct 5 ms 7552 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7296 KB Output is correct
9 Correct 5 ms 7296 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7416 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 6 ms 7296 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7296 KB Output is correct
4 Correct 5 ms 7296 KB Output is correct
5 Correct 5 ms 7552 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7296 KB Output is correct
9 Correct 5 ms 7296 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7416 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 6 ms 7296 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
22 Correct 7 ms 7424 KB Output is correct
23 Correct 7 ms 7424 KB Output is correct
24 Correct 7 ms 7424 KB Output is correct
25 Correct 7 ms 7424 KB Output is correct
26 Correct 7 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
28 Correct 8 ms 7552 KB Output is correct
29 Correct 8 ms 7552 KB Output is correct
30 Correct 8 ms 7552 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 7 ms 7424 KB Output is correct
33 Correct 7 ms 7424 KB Output is correct
34 Correct 7 ms 7424 KB Output is correct
35 Correct 7 ms 7424 KB Output is correct
36 Correct 7 ms 7424 KB Output is correct
37 Correct 7 ms 7424 KB Output is correct
38 Correct 7 ms 7424 KB Output is correct
39 Correct 7 ms 7552 KB Output is correct
40 Correct 8 ms 7552 KB Output is correct
41 Correct 7 ms 7552 KB Output is correct
42 Correct 7 ms 7424 KB Output is correct
43 Correct 8 ms 7424 KB Output is correct
44 Correct 7 ms 7424 KB Output is correct
45 Correct 7 ms 7424 KB Output is correct
46 Correct 8 ms 7424 KB Output is correct
47 Correct 7 ms 7424 KB Output is correct
48 Correct 8 ms 7552 KB Output is correct
49 Correct 7 ms 7552 KB Output is correct
50 Correct 7 ms 7552 KB Output is correct
51 Correct 9 ms 7552 KB Output is correct
52 Correct 7 ms 7424 KB Output is correct
53 Correct 7 ms 7424 KB Output is correct
54 Correct 7 ms 7424 KB Output is correct
55 Correct 7 ms 7424 KB Output is correct
56 Correct 7 ms 7424 KB Output is correct
57 Correct 7 ms 7552 KB Output is correct
58 Correct 7 ms 7424 KB Output is correct
59 Correct 7 ms 7424 KB Output is correct
60 Correct 7 ms 7560 KB Output is correct
61 Correct 7 ms 7424 KB Output is correct
62 Correct 7 ms 7552 KB Output is correct
63 Correct 7 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7296 KB Output is correct
4 Correct 5 ms 7296 KB Output is correct
5 Correct 5 ms 7552 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7296 KB Output is correct
9 Correct 5 ms 7296 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7416 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 6 ms 7296 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
22 Correct 7 ms 7424 KB Output is correct
23 Correct 7 ms 7424 KB Output is correct
24 Correct 7 ms 7424 KB Output is correct
25 Correct 7 ms 7424 KB Output is correct
26 Correct 7 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
28 Correct 8 ms 7552 KB Output is correct
29 Correct 8 ms 7552 KB Output is correct
30 Correct 8 ms 7552 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 7 ms 7424 KB Output is correct
33 Correct 7 ms 7424 KB Output is correct
34 Correct 7 ms 7424 KB Output is correct
35 Correct 7 ms 7424 KB Output is correct
36 Correct 7 ms 7424 KB Output is correct
37 Correct 7 ms 7424 KB Output is correct
38 Correct 7 ms 7424 KB Output is correct
39 Correct 7 ms 7552 KB Output is correct
40 Correct 8 ms 7552 KB Output is correct
41 Correct 7 ms 7552 KB Output is correct
42 Correct 7 ms 7424 KB Output is correct
43 Correct 8 ms 7424 KB Output is correct
44 Correct 7 ms 7424 KB Output is correct
45 Correct 7 ms 7424 KB Output is correct
46 Correct 8 ms 7424 KB Output is correct
47 Correct 7 ms 7424 KB Output is correct
48 Correct 8 ms 7552 KB Output is correct
49 Correct 7 ms 7552 KB Output is correct
50 Correct 7 ms 7552 KB Output is correct
51 Correct 9 ms 7552 KB Output is correct
52 Correct 7 ms 7424 KB Output is correct
53 Correct 7 ms 7424 KB Output is correct
54 Correct 7 ms 7424 KB Output is correct
55 Correct 7 ms 7424 KB Output is correct
56 Correct 7 ms 7424 KB Output is correct
57 Correct 7 ms 7552 KB Output is correct
58 Correct 7 ms 7424 KB Output is correct
59 Correct 7 ms 7424 KB Output is correct
60 Correct 7 ms 7560 KB Output is correct
61 Correct 7 ms 7424 KB Output is correct
62 Correct 7 ms 7552 KB Output is correct
63 Correct 7 ms 7424 KB Output is correct
64 Correct 383 ms 17416 KB Output is correct
65 Correct 382 ms 17288 KB Output is correct
66 Correct 375 ms 17284 KB Output is correct
67 Correct 369 ms 17288 KB Output is correct
68 Correct 376 ms 17328 KB Output is correct
69 Correct 378 ms 17244 KB Output is correct
70 Correct 372 ms 17160 KB Output is correct
71 Correct 374 ms 17284 KB Output is correct
72 Correct 374 ms 17288 KB Output is correct
73 Correct 393 ms 29960 KB Output is correct
74 Correct 393 ms 29832 KB Output is correct
75 Correct 369 ms 17160 KB Output is correct
76 Correct 375 ms 17416 KB Output is correct
77 Correct 377 ms 17160 KB Output is correct
78 Correct 384 ms 17288 KB Output is correct
79 Correct 383 ms 17160 KB Output is correct
80 Correct 383 ms 17200 KB Output is correct
81 Correct 341 ms 17396 KB Output is correct
82 Correct 366 ms 17140 KB Output is correct
83 Correct 383 ms 22328 KB Output is correct
84 Correct 389 ms 24456 KB Output is correct
85 Correct 385 ms 24072 KB Output is correct
86 Correct 378 ms 18440 KB Output is correct
87 Correct 375 ms 17928 KB Output is correct
88 Correct 376 ms 18376 KB Output is correct
89 Correct 359 ms 18312 KB Output is correct
90 Correct 360 ms 18184 KB Output is correct
91 Correct 373 ms 18312 KB Output is correct
92 Correct 372 ms 18676 KB Output is correct
93 Correct 359 ms 21216 KB Output is correct
94 Correct 345 ms 22768 KB Output is correct
95 Correct 349 ms 21496 KB Output is correct
96 Correct 363 ms 19720 KB Output is correct
97 Correct 353 ms 18312 KB Output is correct
98 Correct 356 ms 17672 KB Output is correct
99 Correct 375 ms 17436 KB Output is correct
100 Correct 373 ms 20616 KB Output is correct
101 Correct 369 ms 18572 KB Output is correct
102 Correct 366 ms 17928 KB Output is correct
103 Correct 371 ms 17672 KB Output is correct
104 Correct 312 ms 17644 KB Output is correct
105 Correct 388 ms 26504 KB Output is correct
106 Correct 292 ms 17644 KB Output is correct
107 Correct 300 ms 17768 KB Output is correct
108 Correct 412 ms 30468 KB Output is correct
109 Correct 309 ms 17688 KB Output is correct
110 Correct 395 ms 30856 KB Output is correct
111 Correct 367 ms 17160 KB Output is correct