답안 #465453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465453 2021-08-16T07:14:29 Z ohasanov Power Plant (JOI20_power) C++17
100 / 100
184 ms 28872 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 200000 + 5;
vector <int> g[N];
int prelist[N], n;
string a;

int dfs(int node, int father)
{
    int st = a[node-1] - '0', best_child = 0, best = 0;
    for (int i = 0; i < (int)g[node].size(); i++)
    {
		int x = g[node][i];
        if (x != father){
			best = max(best, dfs(x, node));
			prelist[node] += prelist[x];
			best_child = max(best_child, prelist[x]);
		}
    }
    prelist[node] = max(st, prelist[node] - st);
    return max(best, max(prelist[node], best_child + st));
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin >> a;
    cout << dfs(1, 0);
	
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 5012 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 3 ms 5016 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4940 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 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 5012 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 3 ms 5016 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5028 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5020 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5156 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 4 ms 5096 KB Output is correct
32 Correct 5 ms 5032 KB Output is correct
33 Correct 5 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 4 ms 5064 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5156 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 4 ms 5068 KB Output is correct
52 Correct 5 ms 5028 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 4 ms 5120 KB Output is correct
56 Correct 4 ms 5068 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5028 KB Output is correct
59 Correct 4 ms 5048 KB Output is correct
60 Correct 4 ms 5068 KB Output is correct
61 Correct 4 ms 5068 KB Output is correct
62 Correct 4 ms 5164 KB Output is correct
63 Correct 4 ms 5068 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 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 5012 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 5016 KB Output is correct
14 Correct 3 ms 5016 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5028 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5020 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5156 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 4 ms 5096 KB Output is correct
32 Correct 5 ms 5032 KB Output is correct
33 Correct 5 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 4 ms 5064 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5156 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 4 ms 5068 KB Output is correct
52 Correct 5 ms 5028 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 4 ms 5120 KB Output is correct
56 Correct 4 ms 5068 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5028 KB Output is correct
59 Correct 4 ms 5048 KB Output is correct
60 Correct 4 ms 5068 KB Output is correct
61 Correct 4 ms 5068 KB Output is correct
62 Correct 4 ms 5164 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 149 ms 15096 KB Output is correct
65 Correct 147 ms 15364 KB Output is correct
66 Correct 157 ms 15080 KB Output is correct
67 Correct 139 ms 15272 KB Output is correct
68 Correct 166 ms 15116 KB Output is correct
69 Correct 161 ms 15124 KB Output is correct
70 Correct 133 ms 15136 KB Output is correct
71 Correct 134 ms 15084 KB Output is correct
72 Correct 135 ms 15104 KB Output is correct
73 Correct 184 ms 27828 KB Output is correct
74 Correct 155 ms 27660 KB Output is correct
75 Correct 133 ms 15060 KB Output is correct
76 Correct 136 ms 14988 KB Output is correct
77 Correct 146 ms 15016 KB Output is correct
78 Correct 133 ms 14976 KB Output is correct
79 Correct 137 ms 14988 KB Output is correct
80 Correct 150 ms 15028 KB Output is correct
81 Correct 123 ms 15516 KB Output is correct
82 Correct 127 ms 15172 KB Output is correct
83 Correct 141 ms 20208 KB Output is correct
84 Correct 144 ms 22364 KB Output is correct
85 Correct 170 ms 22104 KB Output is correct
86 Correct 152 ms 16460 KB Output is correct
87 Correct 138 ms 15924 KB Output is correct
88 Correct 144 ms 16320 KB Output is correct
89 Correct 157 ms 16376 KB Output is correct
90 Correct 126 ms 16196 KB Output is correct
91 Correct 127 ms 16448 KB Output is correct
92 Correct 127 ms 16752 KB Output is correct
93 Correct 165 ms 19112 KB Output is correct
94 Correct 126 ms 20924 KB Output is correct
95 Correct 119 ms 19512 KB Output is correct
96 Correct 132 ms 17788 KB Output is correct
97 Correct 128 ms 16264 KB Output is correct
98 Correct 135 ms 15924 KB Output is correct
99 Correct 131 ms 15452 KB Output is correct
100 Correct 136 ms 18704 KB Output is correct
101 Correct 137 ms 16784 KB Output is correct
102 Correct 124 ms 15956 KB Output is correct
103 Correct 144 ms 15656 KB Output is correct
104 Correct 83 ms 16012 KB Output is correct
105 Correct 160 ms 24612 KB Output is correct
106 Correct 83 ms 15928 KB Output is correct
107 Correct 98 ms 15928 KB Output is correct
108 Correct 157 ms 28556 KB Output is correct
109 Correct 89 ms 15976 KB Output is correct
110 Correct 169 ms 28872 KB Output is correct
111 Correct 128 ms 15092 KB Output is correct