답안 #292581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292581 2020-09-07T10:06:26 Z model_code Power Plant (JOI20_power) C++17
100 / 100
423 ms 26252 KB
#include <bits/stdc++.h>
using namespace std;

#define SIZE 200000

void chmax(int &a,int b){
    if(a<b)a=b;
}

int n,ans;
vector<int>g[SIZE];
int E[SIZE],dp[SIZE];

void dfs(int v,int p){
    int sum=0,ma=0;
    for(int &i:g[v]){
        if(i==p)continue;
        dfs(i,v);
        sum+=dp[i];
        chmax(ma,dp[i]);
    }
    if(E[v]==1){
        chmax(ans,max(ma+1,sum-1));
    }else{
        chmax(ans,sum);
    }
    dp[v]=max(E[v],sum-E[v]);
}

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='1')E[i]=1;
    }
    dfs(0,-1);
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4968 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4976 KB Output is correct
19 Correct 4 ms 4992 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4968 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4976 KB Output is correct
19 Correct 4 ms 4992 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 5152 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 6 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 6 ms 5120 KB Output is correct
29 Correct 6 ms 5248 KB Output is correct
30 Correct 6 ms 5248 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 6 ms 5120 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 6 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 6 ms 5120 KB Output is correct
39 Correct 6 ms 5120 KB Output is correct
40 Correct 6 ms 5120 KB Output is correct
41 Correct 6 ms 5120 KB Output is correct
42 Correct 6 ms 5120 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 6 ms 5120 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 6 ms 5120 KB Output is correct
47 Correct 6 ms 5120 KB Output is correct
48 Correct 6 ms 5120 KB Output is correct
49 Correct 6 ms 5120 KB Output is correct
50 Correct 6 ms 5248 KB Output is correct
51 Correct 6 ms 5120 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 6 ms 5120 KB Output is correct
54 Correct 6 ms 5120 KB Output is correct
55 Correct 6 ms 5120 KB Output is correct
56 Correct 6 ms 5120 KB Output is correct
57 Correct 6 ms 5248 KB Output is correct
58 Correct 6 ms 5120 KB Output is correct
59 Correct 6 ms 5120 KB Output is correct
60 Correct 6 ms 5120 KB Output is correct
61 Correct 6 ms 5120 KB Output is correct
62 Correct 6 ms 5248 KB Output is correct
63 Correct 6 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4968 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4976 KB Output is correct
19 Correct 4 ms 4992 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 5152 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 6 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 6 ms 5120 KB Output is correct
29 Correct 6 ms 5248 KB Output is correct
30 Correct 6 ms 5248 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 6 ms 5120 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 6 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 6 ms 5120 KB Output is correct
39 Correct 6 ms 5120 KB Output is correct
40 Correct 6 ms 5120 KB Output is correct
41 Correct 6 ms 5120 KB Output is correct
42 Correct 6 ms 5120 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 6 ms 5120 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 6 ms 5120 KB Output is correct
47 Correct 6 ms 5120 KB Output is correct
48 Correct 6 ms 5120 KB Output is correct
49 Correct 6 ms 5120 KB Output is correct
50 Correct 6 ms 5248 KB Output is correct
51 Correct 6 ms 5120 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 6 ms 5120 KB Output is correct
54 Correct 6 ms 5120 KB Output is correct
55 Correct 6 ms 5120 KB Output is correct
56 Correct 6 ms 5120 KB Output is correct
57 Correct 6 ms 5248 KB Output is correct
58 Correct 6 ms 5120 KB Output is correct
59 Correct 6 ms 5120 KB Output is correct
60 Correct 6 ms 5120 KB Output is correct
61 Correct 6 ms 5120 KB Output is correct
62 Correct 6 ms 5248 KB Output is correct
63 Correct 6 ms 5120 KB Output is correct
64 Correct 374 ms 13320 KB Output is correct
65 Correct 370 ms 13320 KB Output is correct
66 Correct 367 ms 13316 KB Output is correct
67 Correct 372 ms 13320 KB Output is correct
68 Correct 366 ms 13340 KB Output is correct
69 Correct 369 ms 13400 KB Output is correct
70 Correct 372 ms 13320 KB Output is correct
71 Correct 382 ms 13228 KB Output is correct
72 Correct 417 ms 12552 KB Output is correct
73 Correct 405 ms 25864 KB Output is correct
74 Correct 421 ms 25832 KB Output is correct
75 Correct 417 ms 13220 KB Output is correct
76 Correct 390 ms 13148 KB Output is correct
77 Correct 388 ms 13140 KB Output is correct
78 Correct 383 ms 13156 KB Output is correct
79 Correct 390 ms 13192 KB Output is correct
80 Correct 379 ms 13192 KB Output is correct
81 Correct 343 ms 13676 KB Output is correct
82 Correct 372 ms 13468 KB Output is correct
83 Correct 391 ms 18440 KB Output is correct
84 Correct 388 ms 20492 KB Output is correct
85 Correct 394 ms 20232 KB Output is correct
86 Correct 386 ms 14728 KB Output is correct
87 Correct 379 ms 14216 KB Output is correct
88 Correct 372 ms 14472 KB Output is correct
89 Correct 367 ms 14600 KB Output is correct
90 Correct 370 ms 14344 KB Output is correct
91 Correct 371 ms 14600 KB Output is correct
92 Correct 370 ms 14892 KB Output is correct
93 Correct 372 ms 17280 KB Output is correct
94 Correct 350 ms 19184 KB Output is correct
95 Correct 358 ms 17668 KB Output is correct
96 Correct 369 ms 15880 KB Output is correct
97 Correct 423 ms 14352 KB Output is correct
98 Correct 369 ms 13892 KB Output is correct
99 Correct 373 ms 13576 KB Output is correct
100 Correct 367 ms 16776 KB Output is correct
101 Correct 371 ms 14728 KB Output is correct
102 Correct 360 ms 14088 KB Output is correct
103 Correct 367 ms 13832 KB Output is correct
104 Correct 317 ms 13296 KB Output is correct
105 Correct 402 ms 21896 KB Output is correct
106 Correct 295 ms 14056 KB Output is correct
107 Correct 307 ms 14056 KB Output is correct
108 Correct 385 ms 25864 KB Output is correct
109 Correct 327 ms 13280 KB Output is correct
110 Correct 412 ms 26252 KB Output is correct
111 Correct 374 ms 13204 KB Output is correct