답안 #358517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
358517 2021-01-25T15:53:34 Z BartolM Power Plant (JOI20_power) C++17
100 / 100
315 ms 30188 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=2e5+5;

int n;
vector <int> ls[N];
int val[N], un[N], iz[N];
int sol=0;

void dfs(int node, int par) {
    un[node]=val[node];
    int uk=0;
    for (int sus:ls[node]) {
        if (sus==par) continue;
        dfs(sus, node);
        uk+=un[sus];
    }
    un[node]=max(un[node], uk-val[node]);
}

void rek(int node, int par) {
    int uk=iz[node];
    for (int sus:ls[node]) if (sus!=par) uk+=un[sus];

    for (int sus:ls[node]) {
        if (sus==par) continue;
        iz[sus]=max(val[node], uk-un[sus]-val[node]);
        rek(sus, node);
    }
    if (val[node]) {
        sol=max(sol, uk-1);
        sol=max(sol, iz[node]+1);
        for (int sus:ls[node]) if (sus!=par) sol=max(sol, un[sus]+1);
    }
}

void load() {
    scanf("%d", &n);
    for (int i=0; i<n-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        ls[a].pb(b); ls[b].pb(a);
    }
    for (int i=1; i<=n; ++i) {
        char c;
        scanf(" %c", &c);
        val[i]=c-'0';
    }
}

int main() {
    load();

    dfs(1, 0);
    rek(1, 0);
//    for (int i=1; i<=n; ++i) {
//        printf("i: %d, un: %d, iz: %d\n",i, un[i], iz[i]);
//    }
    printf("%d\n", sol);
    return 0;
}

Compilation message

power.cpp: In function 'void load()':
power.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
power.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
power.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |         scanf(" %c", &c);
      |         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 4 ms 4972 KB Output is correct
13 Correct 4 ms 4972 KB Output is correct
14 Correct 4 ms 4972 KB Output is correct
15 Correct 4 ms 4972 KB Output is correct
16 Correct 4 ms 4972 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4972 KB Output is correct
19 Correct 4 ms 4972 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 4 ms 4972 KB Output is correct
13 Correct 4 ms 4972 KB Output is correct
14 Correct 4 ms 4972 KB Output is correct
15 Correct 4 ms 4972 KB Output is correct
16 Correct 4 ms 4972 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4972 KB Output is correct
19 Correct 4 ms 4972 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 5 ms 5080 KB Output is correct
23 Correct 5 ms 5100 KB Output is correct
24 Correct 5 ms 5100 KB Output is correct
25 Correct 6 ms 5100 KB Output is correct
26 Correct 5 ms 5100 KB Output is correct
27 Correct 5 ms 5100 KB Output is correct
28 Correct 5 ms 5100 KB Output is correct
29 Correct 5 ms 5228 KB Output is correct
30 Correct 5 ms 5228 KB Output is correct
31 Correct 5 ms 5100 KB Output is correct
32 Correct 5 ms 5100 KB Output is correct
33 Correct 4 ms 5100 KB Output is correct
34 Correct 5 ms 5100 KB Output is correct
35 Correct 5 ms 5228 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 4 ms 5100 KB Output is correct
38 Correct 5 ms 5100 KB Output is correct
39 Correct 5 ms 5228 KB Output is correct
40 Correct 6 ms 5228 KB Output is correct
41 Correct 5 ms 5228 KB Output is correct
42 Correct 5 ms 5100 KB Output is correct
43 Correct 5 ms 5100 KB Output is correct
44 Correct 5 ms 5228 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
46 Correct 5 ms 5100 KB Output is correct
47 Correct 5 ms 5100 KB Output is correct
48 Correct 5 ms 5228 KB Output is correct
49 Correct 5 ms 5228 KB Output is correct
50 Correct 5 ms 5228 KB Output is correct
51 Correct 5 ms 5228 KB Output is correct
52 Correct 5 ms 5100 KB Output is correct
53 Correct 5 ms 5228 KB Output is correct
54 Correct 5 ms 5100 KB Output is correct
55 Correct 5 ms 5100 KB Output is correct
56 Correct 5 ms 5100 KB Output is correct
57 Correct 5 ms 5228 KB Output is correct
58 Correct 5 ms 5100 KB Output is correct
59 Correct 5 ms 5260 KB Output is correct
60 Correct 5 ms 5228 KB Output is correct
61 Correct 5 ms 5100 KB Output is correct
62 Correct 5 ms 5228 KB Output is correct
63 Correct 5 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 4 ms 4972 KB Output is correct
13 Correct 4 ms 4972 KB Output is correct
14 Correct 4 ms 4972 KB Output is correct
15 Correct 4 ms 4972 KB Output is correct
16 Correct 4 ms 4972 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4972 KB Output is correct
19 Correct 4 ms 4972 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 5 ms 5080 KB Output is correct
23 Correct 5 ms 5100 KB Output is correct
24 Correct 5 ms 5100 KB Output is correct
25 Correct 6 ms 5100 KB Output is correct
26 Correct 5 ms 5100 KB Output is correct
27 Correct 5 ms 5100 KB Output is correct
28 Correct 5 ms 5100 KB Output is correct
29 Correct 5 ms 5228 KB Output is correct
30 Correct 5 ms 5228 KB Output is correct
31 Correct 5 ms 5100 KB Output is correct
32 Correct 5 ms 5100 KB Output is correct
33 Correct 4 ms 5100 KB Output is correct
34 Correct 5 ms 5100 KB Output is correct
35 Correct 5 ms 5228 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 4 ms 5100 KB Output is correct
38 Correct 5 ms 5100 KB Output is correct
39 Correct 5 ms 5228 KB Output is correct
40 Correct 6 ms 5228 KB Output is correct
41 Correct 5 ms 5228 KB Output is correct
42 Correct 5 ms 5100 KB Output is correct
43 Correct 5 ms 5100 KB Output is correct
44 Correct 5 ms 5228 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
46 Correct 5 ms 5100 KB Output is correct
47 Correct 5 ms 5100 KB Output is correct
48 Correct 5 ms 5228 KB Output is correct
49 Correct 5 ms 5228 KB Output is correct
50 Correct 5 ms 5228 KB Output is correct
51 Correct 5 ms 5228 KB Output is correct
52 Correct 5 ms 5100 KB Output is correct
53 Correct 5 ms 5228 KB Output is correct
54 Correct 5 ms 5100 KB Output is correct
55 Correct 5 ms 5100 KB Output is correct
56 Correct 5 ms 5100 KB Output is correct
57 Correct 5 ms 5228 KB Output is correct
58 Correct 5 ms 5100 KB Output is correct
59 Correct 5 ms 5260 KB Output is correct
60 Correct 5 ms 5228 KB Output is correct
61 Correct 5 ms 5100 KB Output is correct
62 Correct 5 ms 5228 KB Output is correct
63 Correct 5 ms 5100 KB Output is correct
64 Correct 296 ms 16492 KB Output is correct
65 Correct 229 ms 16492 KB Output is correct
66 Correct 232 ms 16492 KB Output is correct
67 Correct 230 ms 16468 KB Output is correct
68 Correct 224 ms 16492 KB Output is correct
69 Correct 225 ms 16492 KB Output is correct
70 Correct 217 ms 16492 KB Output is correct
71 Correct 219 ms 16620 KB Output is correct
72 Correct 230 ms 16492 KB Output is correct
73 Correct 315 ms 29092 KB Output is correct
74 Correct 271 ms 29184 KB Output is correct
75 Correct 207 ms 16364 KB Output is correct
76 Correct 225 ms 16364 KB Output is correct
77 Correct 249 ms 16516 KB Output is correct
78 Correct 234 ms 16364 KB Output is correct
79 Correct 241 ms 16480 KB Output is correct
80 Correct 231 ms 16364 KB Output is correct
81 Correct 202 ms 16760 KB Output is correct
82 Correct 219 ms 16616 KB Output is correct
83 Correct 241 ms 21612 KB Output is correct
84 Correct 241 ms 23916 KB Output is correct
85 Correct 244 ms 23356 KB Output is correct
86 Correct 232 ms 17820 KB Output is correct
87 Correct 230 ms 17260 KB Output is correct
88 Correct 233 ms 17724 KB Output is correct
89 Correct 218 ms 17772 KB Output is correct
90 Correct 218 ms 17516 KB Output is correct
91 Correct 213 ms 17772 KB Output is correct
92 Correct 252 ms 18028 KB Output is correct
93 Correct 223 ms 20420 KB Output is correct
94 Correct 242 ms 22124 KB Output is correct
95 Correct 212 ms 21112 KB Output is correct
96 Correct 218 ms 19180 KB Output is correct
97 Correct 205 ms 17516 KB Output is correct
98 Correct 200 ms 17092 KB Output is correct
99 Correct 223 ms 16876 KB Output is correct
100 Correct 215 ms 19948 KB Output is correct
101 Correct 223 ms 18156 KB Output is correct
102 Correct 241 ms 17260 KB Output is correct
103 Correct 219 ms 17196 KB Output is correct
104 Correct 126 ms 17376 KB Output is correct
105 Correct 258 ms 25836 KB Output is correct
106 Correct 143 ms 17120 KB Output is correct
107 Correct 127 ms 16992 KB Output is correct
108 Correct 263 ms 29996 KB Output is correct
109 Correct 124 ms 17248 KB Output is correct
110 Correct 251 ms 30188 KB Output is correct
111 Correct 236 ms 16404 KB Output is correct