Submission #1058889

# Submission time Handle Problem Language Result Execution time Memory
1058889 2024-08-14T14:48:39 Z YassirSalama Power Plant (JOI20_power) C++17
100 / 100
119 ms 26852 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const int maxn=2e5+100;
string s;
vector<int> v[maxn];
int dp[maxn];
int ans=0;
void dfs(int node,int par){
    if(s[node]=='1'){
        for(auto x:v[node]){
            if(x==par) continue;
            dfs(x,node);
            dp[node]+=dp[x];
            ans=max(ans,dp[x]+1);
        }
        dp[node]--;
        dp[node]=max(dp[node],1LL);
    }else{
        for(auto x:v[node]){
            if(x==par) continue;
            dfs(x,node);
            dp[node]+=dp[x];
        }
    }
    ans=max(ans,dp[node]);
}
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;a--,b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin>>s;
    dfs(0,0);
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6500 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6496 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6620 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6520 KB Output is correct
45 Correct 2 ms 6540 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6596 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6500 KB Output is correct
50 Correct 2 ms 6564 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 3 ms 6492 KB Output is correct
54 Correct 2 ms 6592 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6492 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 2 ms 6624 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6492 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6500 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6496 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6620 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6520 KB Output is correct
45 Correct 2 ms 6540 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6596 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6500 KB Output is correct
50 Correct 2 ms 6564 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 3 ms 6492 KB Output is correct
54 Correct 2 ms 6592 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6492 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 2 ms 6624 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6492 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
64 Correct 93 ms 16872 KB Output is correct
65 Correct 84 ms 16872 KB Output is correct
66 Correct 86 ms 16836 KB Output is correct
67 Correct 87 ms 16960 KB Output is correct
68 Correct 88 ms 17012 KB Output is correct
69 Correct 86 ms 16896 KB Output is correct
70 Correct 82 ms 16868 KB Output is correct
71 Correct 83 ms 16948 KB Output is correct
72 Correct 82 ms 17020 KB Output is correct
73 Correct 91 ms 26024 KB Output is correct
74 Correct 99 ms 26020 KB Output is correct
75 Correct 110 ms 18152 KB Output is correct
76 Correct 87 ms 18252 KB Output is correct
77 Correct 97 ms 16868 KB Output is correct
78 Correct 83 ms 16868 KB Output is correct
79 Correct 89 ms 16956 KB Output is correct
80 Correct 96 ms 16868 KB Output is correct
81 Correct 81 ms 17144 KB Output is correct
82 Correct 83 ms 17092 KB Output is correct
83 Correct 93 ms 21032 KB Output is correct
84 Correct 90 ms 22812 KB Output is correct
85 Correct 88 ms 22504 KB Output is correct
86 Correct 85 ms 18148 KB Output is correct
87 Correct 84 ms 17636 KB Output is correct
88 Correct 85 ms 17636 KB Output is correct
89 Correct 83 ms 17592 KB Output is correct
90 Correct 85 ms 17576 KB Output is correct
91 Correct 87 ms 17800 KB Output is correct
92 Correct 94 ms 17928 KB Output is correct
93 Correct 119 ms 19728 KB Output is correct
94 Correct 83 ms 20936 KB Output is correct
95 Correct 83 ms 20160 KB Output is correct
96 Correct 87 ms 18684 KB Output is correct
97 Correct 80 ms 17384 KB Output is correct
98 Correct 81 ms 17200 KB Output is correct
99 Correct 85 ms 17128 KB Output is correct
100 Correct 83 ms 19492 KB Output is correct
101 Correct 83 ms 17636 KB Output is correct
102 Correct 79 ms 17128 KB Output is correct
103 Correct 82 ms 17328 KB Output is correct
104 Correct 75 ms 17600 KB Output is correct
105 Correct 88 ms 23524 KB Output is correct
106 Correct 71 ms 17344 KB Output is correct
107 Correct 71 ms 17344 KB Output is correct
108 Correct 110 ms 26596 KB Output is correct
109 Correct 76 ms 17600 KB Output is correct
110 Correct 90 ms 26852 KB Output is correct
111 Correct 79 ms 16868 KB Output is correct