답안 #478805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478805 2021-10-08T12:17:35 Z nicolaalexandra Power Plant (JOI20_power) C++14
100 / 100
324 ms 29552 KB
#include <bits/stdc++.h>
#define DIM 200010
using namespace std;

/// dp[nod] - profit maxim daca iau doar noduri care nu sunt stramosi intre ele

vector <int> L[DIM];
int dp[DIM],f[DIM],cnt[DIM],fth[DIM];
char s[DIM];
int n,x,y,i;

void dfs (int nod, int tata){

    fth[nod] = tata;
    cnt[nod] = f[nod];
    int ok = 0;
    for (auto vecin : L[nod])
        if (vecin != tata){
            ok = 1;
            dfs (vecin,nod);
            cnt[nod] += cnt[vecin];
        }

    if (!ok){
        if (f[nod])
            dp[nod] = 1;
    } else {
        for (auto vecin : L[nod]){
            if (vecin != tata)
                dp[nod] += dp[vecin];
        }

        dp[nod] -= f[nod];

        if (f[nod])
            dp[nod] = max (dp[nod],1);
    }

}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n;
    for (i=1;i<n;i++){
        cin>>x>>y;
        L[x].push_back(y);
        L[y].push_back(x);
    }

    cin>>s+1;

    for (i=1;i<=n;i++)
        f[i] = s[i] - '0';


    dfs (1,0);

    int sol = 0;
    for (i=1;i<=n;i++){
        sol = max (sol,dp[i]);
        for (auto vecin : L[i]){
            if (vecin == fth[i])
                continue;
            sol = max (sol,dp[vecin] + f[i]);
        }
    }

    cout<<sol;

    return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:53:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |     cin>>s+1;
      |          ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 4996 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 5000 KB Output is correct
16 Correct 4 ms 5028 KB Output is correct
17 Correct 3 ms 4996 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 4996 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 5000 KB Output is correct
16 Correct 4 ms 5028 KB Output is correct
17 Correct 3 ms 4996 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 5 ms 5068 KB Output is correct
23 Correct 6 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 6 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5132 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5132 KB Output is correct
36 Correct 4 ms 5136 KB Output is correct
37 Correct 6 ms 5068 KB Output is correct
38 Correct 7 ms 5132 KB Output is correct
39 Correct 5 ms 5140 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5132 KB Output is correct
42 Correct 4 ms 5100 KB Output is correct
43 Correct 4 ms 5140 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 6 ms 5068 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 5 ms 5068 KB Output is correct
48 Correct 5 ms 5196 KB Output is correct
49 Correct 4 ms 5196 KB Output is correct
50 Correct 5 ms 5132 KB Output is correct
51 Correct 6 ms 5068 KB Output is correct
52 Correct 4 ms 5132 KB Output is correct
53 Correct 6 ms 5068 KB Output is correct
54 Correct 5 ms 5136 KB Output is correct
55 Correct 4 ms 5148 KB Output is correct
56 Correct 5 ms 5104 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5092 KB Output is correct
59 Correct 4 ms 5124 KB Output is correct
60 Correct 5 ms 5196 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 4996 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 5000 KB Output is correct
16 Correct 4 ms 5028 KB Output is correct
17 Correct 3 ms 4996 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 5 ms 5068 KB Output is correct
23 Correct 6 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 6 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5132 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5132 KB Output is correct
36 Correct 4 ms 5136 KB Output is correct
37 Correct 6 ms 5068 KB Output is correct
38 Correct 7 ms 5132 KB Output is correct
39 Correct 5 ms 5140 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5132 KB Output is correct
42 Correct 4 ms 5100 KB Output is correct
43 Correct 4 ms 5140 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 6 ms 5068 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 5 ms 5068 KB Output is correct
48 Correct 5 ms 5196 KB Output is correct
49 Correct 4 ms 5196 KB Output is correct
50 Correct 5 ms 5132 KB Output is correct
51 Correct 6 ms 5068 KB Output is correct
52 Correct 4 ms 5132 KB Output is correct
53 Correct 6 ms 5068 KB Output is correct
54 Correct 5 ms 5136 KB Output is correct
55 Correct 4 ms 5148 KB Output is correct
56 Correct 5 ms 5104 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5092 KB Output is correct
59 Correct 4 ms 5124 KB Output is correct
60 Correct 5 ms 5196 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 265 ms 15736 KB Output is correct
65 Correct 234 ms 15680 KB Output is correct
66 Correct 284 ms 15804 KB Output is correct
67 Correct 294 ms 15764 KB Output is correct
68 Correct 259 ms 15756 KB Output is correct
69 Correct 250 ms 15656 KB Output is correct
70 Correct 274 ms 15812 KB Output is correct
71 Correct 247 ms 15776 KB Output is correct
72 Correct 265 ms 15836 KB Output is correct
73 Correct 324 ms 28356 KB Output is correct
74 Correct 271 ms 28304 KB Output is correct
75 Correct 296 ms 15652 KB Output is correct
76 Correct 251 ms 15604 KB Output is correct
77 Correct 257 ms 15684 KB Output is correct
78 Correct 251 ms 15664 KB Output is correct
79 Correct 298 ms 15560 KB Output is correct
80 Correct 244 ms 15772 KB Output is correct
81 Correct 239 ms 16056 KB Output is correct
82 Correct 259 ms 15900 KB Output is correct
83 Correct 285 ms 20848 KB Output is correct
84 Correct 282 ms 23096 KB Output is correct
85 Correct 297 ms 22692 KB Output is correct
86 Correct 263 ms 17008 KB Output is correct
87 Correct 268 ms 16452 KB Output is correct
88 Correct 255 ms 17032 KB Output is correct
89 Correct 261 ms 17016 KB Output is correct
90 Correct 243 ms 16716 KB Output is correct
91 Correct 247 ms 16980 KB Output is correct
92 Correct 235 ms 17416 KB Output is correct
93 Correct 223 ms 19824 KB Output is correct
94 Correct 225 ms 21456 KB Output is correct
95 Correct 219 ms 20080 KB Output is correct
96 Correct 228 ms 18244 KB Output is correct
97 Correct 224 ms 16836 KB Output is correct
98 Correct 221 ms 16376 KB Output is correct
99 Correct 230 ms 16196 KB Output is correct
100 Correct 236 ms 19236 KB Output is correct
101 Correct 232 ms 17284 KB Output is correct
102 Correct 237 ms 16508 KB Output is correct
103 Correct 261 ms 16280 KB Output is correct
104 Correct 184 ms 15604 KB Output is correct
105 Correct 270 ms 25132 KB Output is correct
106 Correct 202 ms 16352 KB Output is correct
107 Correct 174 ms 16368 KB Output is correct
108 Correct 291 ms 29092 KB Output is correct
109 Correct 184 ms 15580 KB Output is correct
110 Correct 304 ms 29552 KB Output is correct
111 Correct 243 ms 15656 KB Output is correct