# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
292590 | 2020-09-07T10:16:28 Z | Pajaraja | Power Plant (JOI20_power) | C++17 | 412 ms | 21484 KB |
#include <bits/stdc++.h> #define MAXN 200007 using namespace std; int dp[MAXN],sol=0,pg[MAXN]; vector<int> g[MAXN]; void dfs(int s,int f) { for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s); dp[s]=pg[s]; int sum=0; for(int i=0;i<g[s].size();i++) sol=max(sol,dp[g[s][i]]+pg[s]); for(int i=0;i<g[s].size();i++) sum+=dp[g[s][i]]; dp[s]=max(dp[s],sum-pg[s]); sol=max(sol,dp[s]); } int main() { int n; cin>>n; for(int i=0;i<n-1;i++) { int t1,t2; cin>>t1>>t2; g[t1].push_back(t2); g[t2].push_back(t1); } string s; cin>>s; for(int i=0;i<n;i++) pg[i+1]=s[i]-'0'; dfs(1,1); cout<<sol; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 3 ms | 5120 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 3 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 5 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 4 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 3 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 3 ms | 5120 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 3 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 5 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 4 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 3 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 6 ms | 5120 KB | Output is correct |
23 | Correct | 6 ms | 5120 KB | Output is correct |
24 | Correct | 6 ms | 5120 KB | Output is correct |
25 | Correct | 6 ms | 5120 KB | Output is correct |
26 | Correct | 6 ms | 5120 KB | Output is correct |
27 | Correct | 6 ms | 5120 KB | Output is correct |
28 | Correct | 6 ms | 5120 KB | Output is correct |
29 | Correct | 6 ms | 5120 KB | Output is correct |
30 | Correct | 7 ms | 5120 KB | Output is correct |
31 | Correct | 6 ms | 5120 KB | Output is correct |
32 | Correct | 6 ms | 5120 KB | Output is correct |
33 | Correct | 6 ms | 5120 KB | Output is correct |
34 | Correct | 6 ms | 5120 KB | Output is correct |
35 | Correct | 6 ms | 5120 KB | Output is correct |
36 | Correct | 6 ms | 5120 KB | Output is correct |
37 | Correct | 6 ms | 5120 KB | Output is correct |
38 | Correct | 6 ms | 5120 KB | Output is correct |
39 | Correct | 6 ms | 5248 KB | Output is correct |
40 | Correct | 6 ms | 5120 KB | Output is correct |
41 | Correct | 6 ms | 5120 KB | Output is correct |
42 | Correct | 7 ms | 5120 KB | Output is correct |
43 | Correct | 6 ms | 5120 KB | Output is correct |
44 | Correct | 6 ms | 5120 KB | Output is correct |
45 | Correct | 6 ms | 5120 KB | Output is correct |
46 | Correct | 6 ms | 5120 KB | Output is correct |
47 | Correct | 6 ms | 5120 KB | Output is correct |
48 | Correct | 6 ms | 5120 KB | Output is correct |
49 | Correct | 6 ms | 5120 KB | Output is correct |
50 | Correct | 6 ms | 5120 KB | Output is correct |
51 | Correct | 6 ms | 5120 KB | Output is correct |
52 | Correct | 7 ms | 5120 KB | Output is correct |
53 | Correct | 6 ms | 5120 KB | Output is correct |
54 | Correct | 6 ms | 5120 KB | Output is correct |
55 | Correct | 6 ms | 5120 KB | Output is correct |
56 | Correct | 6 ms | 5120 KB | Output is correct |
57 | Correct | 6 ms | 5120 KB | Output is correct |
58 | Correct | 6 ms | 5120 KB | Output is correct |
59 | Correct | 6 ms | 5120 KB | Output is correct |
60 | Correct | 6 ms | 5120 KB | Output is correct |
61 | Correct | 6 ms | 5120 KB | Output is correct |
62 | Correct | 6 ms | 5120 KB | Output is correct |
63 | Correct | 6 ms | 5120 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 3 ms | 5120 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 3 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 5 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 4 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 3 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 6 ms | 5120 KB | Output is correct |
23 | Correct | 6 ms | 5120 KB | Output is correct |
24 | Correct | 6 ms | 5120 KB | Output is correct |
25 | Correct | 6 ms | 5120 KB | Output is correct |
26 | Correct | 6 ms | 5120 KB | Output is correct |
27 | Correct | 6 ms | 5120 KB | Output is correct |
28 | Correct | 6 ms | 5120 KB | Output is correct |
29 | Correct | 6 ms | 5120 KB | Output is correct |
30 | Correct | 7 ms | 5120 KB | Output is correct |
31 | Correct | 6 ms | 5120 KB | Output is correct |
32 | Correct | 6 ms | 5120 KB | Output is correct |
33 | Correct | 6 ms | 5120 KB | Output is correct |
34 | Correct | 6 ms | 5120 KB | Output is correct |
35 | Correct | 6 ms | 5120 KB | Output is correct |
36 | Correct | 6 ms | 5120 KB | Output is correct |
37 | Correct | 6 ms | 5120 KB | Output is correct |
38 | Correct | 6 ms | 5120 KB | Output is correct |
39 | Correct | 6 ms | 5248 KB | Output is correct |
40 | Correct | 6 ms | 5120 KB | Output is correct |
41 | Correct | 6 ms | 5120 KB | Output is correct |
42 | Correct | 7 ms | 5120 KB | Output is correct |
43 | Correct | 6 ms | 5120 KB | Output is correct |
44 | Correct | 6 ms | 5120 KB | Output is correct |
45 | Correct | 6 ms | 5120 KB | Output is correct |
46 | Correct | 6 ms | 5120 KB | Output is correct |
47 | Correct | 6 ms | 5120 KB | Output is correct |
48 | Correct | 6 ms | 5120 KB | Output is correct |
49 | Correct | 6 ms | 5120 KB | Output is correct |
50 | Correct | 6 ms | 5120 KB | Output is correct |
51 | Correct | 6 ms | 5120 KB | Output is correct |
52 | Correct | 7 ms | 5120 KB | Output is correct |
53 | Correct | 6 ms | 5120 KB | Output is correct |
54 | Correct | 6 ms | 5120 KB | Output is correct |
55 | Correct | 6 ms | 5120 KB | Output is correct |
56 | Correct | 6 ms | 5120 KB | Output is correct |
57 | Correct | 6 ms | 5120 KB | Output is correct |
58 | Correct | 6 ms | 5120 KB | Output is correct |
59 | Correct | 6 ms | 5120 KB | Output is correct |
60 | Correct | 6 ms | 5120 KB | Output is correct |
61 | Correct | 6 ms | 5120 KB | Output is correct |
62 | Correct | 6 ms | 5120 KB | Output is correct |
63 | Correct | 6 ms | 5120 KB | Output is correct |
64 | Correct | 407 ms | 13448 KB | Output is correct |
65 | Correct | 380 ms | 13320 KB | Output is correct |
66 | Correct | 398 ms | 13280 KB | Output is correct |
67 | Correct | 384 ms | 13324 KB | Output is correct |
68 | Correct | 378 ms | 13384 KB | Output is correct |
69 | Correct | 374 ms | 13192 KB | Output is correct |
70 | Correct | 382 ms | 13448 KB | Output is correct |
71 | Correct | 378 ms | 13316 KB | Output is correct |
72 | Correct | 381 ms | 13320 KB | Output is correct |
73 | Correct | 412 ms | 20872 KB | Output is correct |
74 | Correct | 401 ms | 20872 KB | Output is correct |
75 | Correct | 376 ms | 13320 KB | Output is correct |
76 | Correct | 369 ms | 13320 KB | Output is correct |
77 | Correct | 385 ms | 13304 KB | Output is correct |
78 | Correct | 390 ms | 13192 KB | Output is correct |
79 | Correct | 385 ms | 13320 KB | Output is correct |
80 | Correct | 385 ms | 13320 KB | Output is correct |
81 | Correct | 344 ms | 13680 KB | Output is correct |
82 | Correct | 378 ms | 13684 KB | Output is correct |
83 | Correct | 397 ms | 16264 KB | Output is correct |
84 | Correct | 394 ms | 17544 KB | Output is correct |
85 | Correct | 396 ms | 17472 KB | Output is correct |
86 | Correct | 388 ms | 14084 KB | Output is correct |
87 | Correct | 397 ms | 13772 KB | Output is correct |
88 | Correct | 379 ms | 14344 KB | Output is correct |
89 | Correct | 368 ms | 14252 KB | Output is correct |
90 | Correct | 371 ms | 14216 KB | Output is correct |
91 | Correct | 388 ms | 14184 KB | Output is correct |
92 | Correct | 376 ms | 14536 KB | Output is correct |
93 | Correct | 368 ms | 15744 KB | Output is correct |
94 | Correct | 364 ms | 16992 KB | Output is correct |
95 | Correct | 364 ms | 16116 KB | Output is correct |
96 | Correct | 374 ms | 14984 KB | Output is correct |
97 | Correct | 362 ms | 14088 KB | Output is correct |
98 | Correct | 366 ms | 13848 KB | Output is correct |
99 | Correct | 375 ms | 13716 KB | Output is correct |
100 | Correct | 379 ms | 15496 KB | Output is correct |
101 | Correct | 376 ms | 14264 KB | Output is correct |
102 | Correct | 374 ms | 13960 KB | Output is correct |
103 | Correct | 382 ms | 13960 KB | Output is correct |
104 | Correct | 321 ms | 14060 KB | Output is correct |
105 | Correct | 408 ms | 18952 KB | Output is correct |
106 | Correct | 299 ms | 14184 KB | Output is correct |
107 | Correct | 295 ms | 14056 KB | Output is correct |
108 | Correct | 408 ms | 21320 KB | Output is correct |
109 | Correct | 309 ms | 14056 KB | Output is correct |
110 | Correct | 402 ms | 21484 KB | Output is correct |
111 | Correct | 367 ms | 13136 KB | Output is correct |