답안 #1114643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114643 2024-11-19T09:53:10 Z Icelast Power Plant (JOI20_power) C++17
100 / 100
145 ms 26800 KB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
void solve(){
    int n;
    cin >> n;
    vector<vector<int>> adj(n+1);
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    string s;
    cin >> s;
    s = ' ' + s;
    vector<int> f(n+1, 0);
    int ans = 1;
    auto dfs = [&](auto dfs, int u, int p) -> void{
        int mx = 0;
        for(int v : adj[u]){
            if(v == p) continue;
            dfs(dfs, v, u);
            f[u] += f[v];
            mx = max(mx, f[v]);
        }
        ans = max(ans, mx + (s[u] == '1'));
        f[u] -= (s[u] == '1');
        f[u] = max(f[u], (int)(s[u] == '1'));
        ans = max(ans, f[u]);
    };
    dfs(dfs, 1, 0);
    cout << ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 592 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 584 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 2 ms 608 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 1 ms 592 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 1 ms 592 KB Output is correct
46 Correct 1 ms 592 KB Output is correct
47 Correct 1 ms 592 KB Output is correct
48 Correct 2 ms 592 KB Output is correct
49 Correct 1 ms 592 KB Output is correct
50 Correct 1 ms 476 KB Output is correct
51 Correct 1 ms 592 KB Output is correct
52 Correct 1 ms 472 KB Output is correct
53 Correct 1 ms 592 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 1 ms 760 KB Output is correct
56 Correct 1 ms 592 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 1 ms 592 KB Output is correct
59 Correct 2 ms 592 KB Output is correct
60 Correct 1 ms 592 KB Output is correct
61 Correct 1 ms 592 KB Output is correct
62 Correct 1 ms 592 KB Output is correct
63 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 592 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 584 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 2 ms 608 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 1 ms 592 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 1 ms 592 KB Output is correct
46 Correct 1 ms 592 KB Output is correct
47 Correct 1 ms 592 KB Output is correct
48 Correct 2 ms 592 KB Output is correct
49 Correct 1 ms 592 KB Output is correct
50 Correct 1 ms 476 KB Output is correct
51 Correct 1 ms 592 KB Output is correct
52 Correct 1 ms 472 KB Output is correct
53 Correct 1 ms 592 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 1 ms 760 KB Output is correct
56 Correct 1 ms 592 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 1 ms 592 KB Output is correct
59 Correct 2 ms 592 KB Output is correct
60 Correct 1 ms 592 KB Output is correct
61 Correct 1 ms 592 KB Output is correct
62 Correct 1 ms 592 KB Output is correct
63 Correct 2 ms 592 KB Output is correct
64 Correct 57 ms 15304 KB Output is correct
65 Correct 68 ms 15236 KB Output is correct
66 Correct 59 ms 15328 KB Output is correct
67 Correct 65 ms 15180 KB Output is correct
68 Correct 64 ms 15280 KB Output is correct
69 Correct 86 ms 15248 KB Output is correct
70 Correct 91 ms 15088 KB Output is correct
71 Correct 89 ms 15312 KB Output is correct
72 Correct 71 ms 15164 KB Output is correct
73 Correct 145 ms 25892 KB Output is correct
74 Correct 80 ms 25540 KB Output is correct
75 Correct 61 ms 15044 KB Output is correct
76 Correct 82 ms 15160 KB Output is correct
77 Correct 91 ms 14996 KB Output is correct
78 Correct 142 ms 15044 KB Output is correct
79 Correct 68 ms 15184 KB Output is correct
80 Correct 68 ms 15040 KB Output is correct
81 Correct 81 ms 15560 KB Output is correct
82 Correct 67 ms 15240 KB Output is correct
83 Correct 60 ms 19400 KB Output is correct
84 Correct 67 ms 21184 KB Output is correct
85 Correct 76 ms 21200 KB Output is correct
86 Correct 72 ms 16236 KB Output is correct
87 Correct 59 ms 15812 KB Output is correct
88 Correct 62 ms 16384 KB Output is correct
89 Correct 87 ms 16336 KB Output is correct
90 Correct 82 ms 16164 KB Output is correct
91 Correct 66 ms 16304 KB Output is correct
92 Correct 82 ms 16560 KB Output is correct
93 Correct 103 ms 18580 KB Output is correct
94 Correct 61 ms 19960 KB Output is correct
95 Correct 64 ms 18944 KB Output is correct
96 Correct 65 ms 17460 KB Output is correct
97 Correct 75 ms 16156 KB Output is correct
98 Correct 73 ms 15872 KB Output is correct
99 Correct 72 ms 15552 KB Output is correct
100 Correct 90 ms 18352 KB Output is correct
101 Correct 90 ms 16396 KB Output is correct
102 Correct 83 ms 15800 KB Output is correct
103 Correct 81 ms 16100 KB Output is correct
104 Correct 46 ms 16072 KB Output is correct
105 Correct 78 ms 22888 KB Output is correct
106 Correct 43 ms 16080 KB Output is correct
107 Correct 47 ms 16068 KB Output is correct
108 Correct 83 ms 26240 KB Output is correct
109 Correct 51 ms 16064 KB Output is correct
110 Correct 114 ms 26800 KB Output is correct
111 Correct 92 ms 15060 KB Output is correct