답안 #640003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640003 2022-09-13T07:53:36 Z colossal_pepe Power Plant (JOI20_power) C++17
47 / 100
1500 ms 62504 KB
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int n;
vector<pair<int, int>> edges;
vector<vector<int>> g;
vector<map<int, int>> dp;
string s;

int dfs(int u, int par) {
    if (dp[u].find(par) != dp[u].end()) return dp[u][par];
    int ret = 0;
    for (int v : g[u]) {
        if (v != par) ret += dfs(v, u);
    }
    if (s[u] == '1') ret = max(1, ret - 1);
    dp[u][par] = ret;
    return ret;
}

int solve() {
    dp.resize(n);
    int ans = 0;
    for (auto [a, b] : edges) {
        ans = max(ans, dfs(a, b) + dfs(b, a));
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    edges.resize(n - 1), g.resize(n);
    for (auto &[a, b] : edges) {
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin >> s;
    cout << max(1, solve()) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 3 ms 700 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 2 ms 724 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 3 ms 716 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 2 ms 724 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 13 ms 724 KB Output is correct
38 Correct 5 ms 724 KB Output is correct
39 Correct 3 ms 716 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 3 ms 708 KB Output is correct
43 Correct 2 ms 712 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 2 ms 724 KB Output is correct
46 Correct 2 ms 724 KB Output is correct
47 Correct 2 ms 724 KB Output is correct
48 Correct 8 ms 724 KB Output is correct
49 Correct 4 ms 724 KB Output is correct
50 Correct 3 ms 724 KB Output is correct
51 Correct 3 ms 716 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 4 ms 724 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 692 KB Output is correct
56 Correct 37 ms 716 KB Output is correct
57 Correct 2 ms 852 KB Output is correct
58 Correct 31 ms 716 KB Output is correct
59 Correct 37 ms 744 KB Output is correct
60 Correct 2 ms 852 KB Output is correct
61 Correct 29 ms 732 KB Output is correct
62 Correct 2 ms 840 KB Output is correct
63 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 3 ms 700 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 2 ms 724 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 3 ms 716 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 2 ms 724 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 13 ms 724 KB Output is correct
38 Correct 5 ms 724 KB Output is correct
39 Correct 3 ms 716 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 3 ms 708 KB Output is correct
43 Correct 2 ms 712 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 2 ms 724 KB Output is correct
46 Correct 2 ms 724 KB Output is correct
47 Correct 2 ms 724 KB Output is correct
48 Correct 8 ms 724 KB Output is correct
49 Correct 4 ms 724 KB Output is correct
50 Correct 3 ms 724 KB Output is correct
51 Correct 3 ms 716 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 4 ms 724 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 692 KB Output is correct
56 Correct 37 ms 716 KB Output is correct
57 Correct 2 ms 852 KB Output is correct
58 Correct 31 ms 716 KB Output is correct
59 Correct 37 ms 744 KB Output is correct
60 Correct 2 ms 852 KB Output is correct
61 Correct 29 ms 732 KB Output is correct
62 Correct 2 ms 840 KB Output is correct
63 Correct 2 ms 724 KB Output is correct
64 Correct 340 ms 43988 KB Output is correct
65 Correct 309 ms 44044 KB Output is correct
66 Correct 336 ms 44060 KB Output is correct
67 Correct 326 ms 43944 KB Output is correct
68 Correct 331 ms 44012 KB Output is correct
69 Correct 342 ms 44060 KB Output is correct
70 Correct 353 ms 44040 KB Output is correct
71 Correct 334 ms 44052 KB Output is correct
72 Correct 331 ms 44168 KB Output is correct
73 Correct 314 ms 54588 KB Output is correct
74 Correct 338 ms 62504 KB Output is correct
75 Correct 307 ms 43904 KB Output is correct
76 Correct 310 ms 44032 KB Output is correct
77 Correct 305 ms 43932 KB Output is correct
78 Correct 316 ms 43868 KB Output is correct
79 Correct 295 ms 43924 KB Output is correct
80 Correct 382 ms 43868 KB Output is correct
81 Execution timed out 1577 ms 35020 KB Time limit exceeded
82 Halted 0 ms 0 KB -