# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
518426 | 2022-01-23T19:09:35 Z | Vladth11 | Power Plant (JOI20_power) | C++14 | 175 ms | 32328 KB |
#include <bits/stdc++.h> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " using namespace std; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <long double, pii> muchie; const ll NMAX = 200001; const ll VMAX = 21; const ll INF = (1LL << 60); const ll MOD = 1000000007; const ll BLOCK = 318; const ll base = 31; const ll nr_of_bits = 60; vector <int> v[NMAX]; string s; int dp[NMAX][2]; void DFS(int node, int p){ if(s[node - 1] == '1'){ dp[node][1] = 1; } int maxim = -2e9, maxim1 = -2e9, maxim2 = 0, sum = 0; for(auto x : v[node]){ if(x == p) continue; DFS(x, node); maxim = max(maxim, dp[x][2]); maxim1 = max(maxim1, dp[x][1]); sum += dp[x][1]; } dp[node][2] = maxim; dp[node][2] = max(dp[node][2], maxim1 + (s[node - 1] == '1')); /// il iau pe cel mai de sus dp[node][1] = max(dp[node][1], sum - (s[node - 1] == '1')); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, i; cin >> n; for(i = 1; i < n; i++){ int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } cin >> s; DFS(1, 0); cout << max(dp[1][1], dp[1][2]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 2 ms | 4940 KB | Output is correct |
4 | Correct | 2 ms | 4940 KB | Output is correct |
5 | Correct | 3 ms | 5020 KB | Output is correct |
6 | Correct | 3 ms | 5020 KB | Output is correct |
7 | Correct | 3 ms | 5020 KB | Output is correct |
8 | Correct | 3 ms | 4940 KB | Output is correct |
9 | Correct | 3 ms | 4940 KB | Output is correct |
10 | Correct | 3 ms | 5020 KB | Output is correct |
11 | Correct | 3 ms | 4940 KB | Output is correct |
12 | Correct | 3 ms | 5068 KB | Output is correct |
13 | Correct | 3 ms | 5068 KB | Output is correct |
14 | Correct | 3 ms | 4940 KB | Output is correct |
15 | Correct | 3 ms | 5016 KB | Output is correct |
16 | Correct | 2 ms | 4940 KB | Output is correct |
17 | Correct | 3 ms | 4940 KB | Output is correct |
18 | Correct | 2 ms | 4940 KB | Output is correct |
19 | Correct | 3 ms | 4940 KB | Output is correct |
20 | Correct | 4 ms | 4940 KB | Output is correct |
21 | Correct | 3 ms | 5020 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 2 ms | 4940 KB | Output is correct |
4 | Correct | 2 ms | 4940 KB | Output is correct |
5 | Correct | 3 ms | 5020 KB | Output is correct |
6 | Correct | 3 ms | 5020 KB | Output is correct |
7 | Correct | 3 ms | 5020 KB | Output is correct |
8 | Correct | 3 ms | 4940 KB | Output is correct |
9 | Correct | 3 ms | 4940 KB | Output is correct |
10 | Correct | 3 ms | 5020 KB | Output is correct |
11 | Correct | 3 ms | 4940 KB | Output is correct |
12 | Correct | 3 ms | 5068 KB | Output is correct |
13 | Correct | 3 ms | 5068 KB | Output is correct |
14 | Correct | 3 ms | 4940 KB | Output is correct |
15 | Correct | 3 ms | 5016 KB | Output is correct |
16 | Correct | 2 ms | 4940 KB | Output is correct |
17 | Correct | 3 ms | 4940 KB | Output is correct |
18 | Correct | 2 ms | 4940 KB | Output is correct |
19 | Correct | 3 ms | 4940 KB | Output is correct |
20 | Correct | 4 ms | 4940 KB | Output is correct |
21 | Correct | 3 ms | 5020 KB | Output is correct |
22 | Correct | 3 ms | 5068 KB | Output is correct |
23 | Correct | 3 ms | 5060 KB | Output is correct |
24 | Correct | 3 ms | 5068 KB | Output is correct |
25 | Correct | 3 ms | 5068 KB | Output is correct |
26 | Correct | 3 ms | 5068 KB | Output is correct |
27 | Correct | 3 ms | 5024 KB | Output is correct |
28 | Correct | 3 ms | 5108 KB | Output is correct |
29 | Correct | 3 ms | 5160 KB | Output is correct |
30 | Correct | 3 ms | 5144 KB | Output is correct |
31 | Correct | 4 ms | 5068 KB | Output is correct |
32 | Correct | 4 ms | 5068 KB | Output is correct |
33 | Correct | 3 ms | 5088 KB | Output is correct |
34 | Correct | 3 ms | 5068 KB | Output is correct |
35 | Correct | 3 ms | 5036 KB | Output is correct |
36 | Correct | 4 ms | 5068 KB | Output is correct |
37 | Correct | 4 ms | 5128 KB | Output is correct |
38 | Correct | 4 ms | 5040 KB | Output is correct |
39 | Correct | 4 ms | 5068 KB | Output is correct |
40 | Correct | 4 ms | 5068 KB | Output is correct |
41 | Correct | 4 ms | 5164 KB | Output is correct |
42 | Correct | 3 ms | 5068 KB | Output is correct |
43 | Correct | 3 ms | 5036 KB | Output is correct |
44 | Correct | 3 ms | 5068 KB | Output is correct |
45 | Correct | 3 ms | 5068 KB | Output is correct |
46 | Correct | 3 ms | 5068 KB | Output is correct |
47 | Correct | 4 ms | 5036 KB | Output is correct |
48 | Correct | 3 ms | 5176 KB | Output is correct |
49 | Correct | 3 ms | 5160 KB | Output is correct |
50 | Correct | 4 ms | 5164 KB | Output is correct |
51 | Correct | 3 ms | 5204 KB | Output is correct |
52 | Correct | 3 ms | 5036 KB | Output is correct |
53 | Correct | 3 ms | 5048 KB | Output is correct |
54 | Correct | 3 ms | 5068 KB | Output is correct |
55 | Correct | 3 ms | 5040 KB | Output is correct |
56 | Correct | 3 ms | 5068 KB | Output is correct |
57 | Correct | 3 ms | 5196 KB | Output is correct |
58 | Correct | 3 ms | 5068 KB | Output is correct |
59 | Correct | 3 ms | 5032 KB | Output is correct |
60 | Correct | 3 ms | 5156 KB | Output is correct |
61 | Correct | 4 ms | 5076 KB | Output is correct |
62 | Correct | 3 ms | 5196 KB | Output is correct |
63 | Correct | 3 ms | 5028 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 2 ms | 4940 KB | Output is correct |
4 | Correct | 2 ms | 4940 KB | Output is correct |
5 | Correct | 3 ms | 5020 KB | Output is correct |
6 | Correct | 3 ms | 5020 KB | Output is correct |
7 | Correct | 3 ms | 5020 KB | Output is correct |
8 | Correct | 3 ms | 4940 KB | Output is correct |
9 | Correct | 3 ms | 4940 KB | Output is correct |
10 | Correct | 3 ms | 5020 KB | Output is correct |
11 | Correct | 3 ms | 4940 KB | Output is correct |
12 | Correct | 3 ms | 5068 KB | Output is correct |
13 | Correct | 3 ms | 5068 KB | Output is correct |
14 | Correct | 3 ms | 4940 KB | Output is correct |
15 | Correct | 3 ms | 5016 KB | Output is correct |
16 | Correct | 2 ms | 4940 KB | Output is correct |
17 | Correct | 3 ms | 4940 KB | Output is correct |
18 | Correct | 2 ms | 4940 KB | Output is correct |
19 | Correct | 3 ms | 4940 KB | Output is correct |
20 | Correct | 4 ms | 4940 KB | Output is correct |
21 | Correct | 3 ms | 5020 KB | Output is correct |
22 | Correct | 3 ms | 5068 KB | Output is correct |
23 | Correct | 3 ms | 5060 KB | Output is correct |
24 | Correct | 3 ms | 5068 KB | Output is correct |
25 | Correct | 3 ms | 5068 KB | Output is correct |
26 | Correct | 3 ms | 5068 KB | Output is correct |
27 | Correct | 3 ms | 5024 KB | Output is correct |
28 | Correct | 3 ms | 5108 KB | Output is correct |
29 | Correct | 3 ms | 5160 KB | Output is correct |
30 | Correct | 3 ms | 5144 KB | Output is correct |
31 | Correct | 4 ms | 5068 KB | Output is correct |
32 | Correct | 4 ms | 5068 KB | Output is correct |
33 | Correct | 3 ms | 5088 KB | Output is correct |
34 | Correct | 3 ms | 5068 KB | Output is correct |
35 | Correct | 3 ms | 5036 KB | Output is correct |
36 | Correct | 4 ms | 5068 KB | Output is correct |
37 | Correct | 4 ms | 5128 KB | Output is correct |
38 | Correct | 4 ms | 5040 KB | Output is correct |
39 | Correct | 4 ms | 5068 KB | Output is correct |
40 | Correct | 4 ms | 5068 KB | Output is correct |
41 | Correct | 4 ms | 5164 KB | Output is correct |
42 | Correct | 3 ms | 5068 KB | Output is correct |
43 | Correct | 3 ms | 5036 KB | Output is correct |
44 | Correct | 3 ms | 5068 KB | Output is correct |
45 | Correct | 3 ms | 5068 KB | Output is correct |
46 | Correct | 3 ms | 5068 KB | Output is correct |
47 | Correct | 4 ms | 5036 KB | Output is correct |
48 | Correct | 3 ms | 5176 KB | Output is correct |
49 | Correct | 3 ms | 5160 KB | Output is correct |
50 | Correct | 4 ms | 5164 KB | Output is correct |
51 | Correct | 3 ms | 5204 KB | Output is correct |
52 | Correct | 3 ms | 5036 KB | Output is correct |
53 | Correct | 3 ms | 5048 KB | Output is correct |
54 | Correct | 3 ms | 5068 KB | Output is correct |
55 | Correct | 3 ms | 5040 KB | Output is correct |
56 | Correct | 3 ms | 5068 KB | Output is correct |
57 | Correct | 3 ms | 5196 KB | Output is correct |
58 | Correct | 3 ms | 5068 KB | Output is correct |
59 | Correct | 3 ms | 5032 KB | Output is correct |
60 | Correct | 3 ms | 5156 KB | Output is correct |
61 | Correct | 4 ms | 5076 KB | Output is correct |
62 | Correct | 3 ms | 5196 KB | Output is correct |
63 | Correct | 3 ms | 5028 KB | Output is correct |
64 | Correct | 126 ms | 15960 KB | Output is correct |
65 | Correct | 126 ms | 16000 KB | Output is correct |
66 | Correct | 123 ms | 15948 KB | Output is correct |
67 | Correct | 132 ms | 15916 KB | Output is correct |
68 | Correct | 114 ms | 15864 KB | Output is correct |
69 | Correct | 113 ms | 15980 KB | Output is correct |
70 | Correct | 109 ms | 15892 KB | Output is correct |
71 | Correct | 111 ms | 15868 KB | Output is correct |
72 | Correct | 110 ms | 15996 KB | Output is correct |
73 | Correct | 146 ms | 31132 KB | Output is correct |
74 | Correct | 137 ms | 31040 KB | Output is correct |
75 | Correct | 107 ms | 15756 KB | Output is correct |
76 | Correct | 130 ms | 15844 KB | Output is correct |
77 | Correct | 120 ms | 15920 KB | Output is correct |
78 | Correct | 122 ms | 15848 KB | Output is correct |
79 | Correct | 119 ms | 15768 KB | Output is correct |
80 | Correct | 110 ms | 15872 KB | Output is correct |
81 | Correct | 90 ms | 16296 KB | Output is correct |
82 | Correct | 125 ms | 15968 KB | Output is correct |
83 | Correct | 118 ms | 22016 KB | Output is correct |
84 | Correct | 126 ms | 24664 KB | Output is correct |
85 | Correct | 126 ms | 24228 KB | Output is correct |
86 | Correct | 124 ms | 17536 KB | Output is correct |
87 | Correct | 115 ms | 16796 KB | Output is correct |
88 | Correct | 117 ms | 17332 KB | Output is correct |
89 | Correct | 108 ms | 17248 KB | Output is correct |
90 | Correct | 151 ms | 17024 KB | Output is correct |
91 | Correct | 114 ms | 17340 KB | Output is correct |
92 | Correct | 118 ms | 17872 KB | Output is correct |
93 | Correct | 109 ms | 20684 KB | Output is correct |
94 | Correct | 99 ms | 22784 KB | Output is correct |
95 | Correct | 100 ms | 21092 KB | Output is correct |
96 | Correct | 124 ms | 19008 KB | Output is correct |
97 | Correct | 104 ms | 17116 KB | Output is correct |
98 | Correct | 122 ms | 16524 KB | Output is correct |
99 | Correct | 104 ms | 16256 KB | Output is correct |
100 | Correct | 109 ms | 20060 KB | Output is correct |
101 | Correct | 110 ms | 17724 KB | Output is correct |
102 | Correct | 100 ms | 16808 KB | Output is correct |
103 | Correct | 109 ms | 16488 KB | Output is correct |
104 | Correct | 62 ms | 16824 KB | Output is correct |
105 | Correct | 127 ms | 27268 KB | Output is correct |
106 | Correct | 95 ms | 16696 KB | Output is correct |
107 | Correct | 66 ms | 16692 KB | Output is correct |
108 | Correct | 175 ms | 32016 KB | Output is correct |
109 | Correct | 65 ms | 16772 KB | Output is correct |
110 | Correct | 130 ms | 32328 KB | Output is correct |
111 | Correct | 98 ms | 15760 KB | Output is correct |