Submission #683772

# Submission time Handle Problem Language Result Execution time Memory
683772 2023-01-19T10:28:33 Z Fysty Power Plant (JOI20_power) C++17
100 / 100
153 ms 32368 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back

const int N=2e5+5;
vector<int> ed[N];
int dp[N],has[N],ans=0;
void dfs(int u,int p)
{
    int mx=0;
    for(int v:ed[u])
    {
        if(v==p) continue;
        dfs(v,u);
        dp[u]+=dp[v];
        mx=max(mx,dp[v]);
    }
    dp[u]-=has[u];
    dp[u]=max(dp[u],has[u]);
    ans=max({ans,dp[u],mx+has[u]});
}
signed main()
{
    MottoHayaku
    int n;
    cin>>n;
    string s;
    rep(i,n-1)
    {
        int u,v;
        cin>>u>>v;
        ed[u].pb(v);
        ed[v].pb(u);
    }
    cin>>s;
    rep(i,n) has[i+1]=(s[i]=='1');
    dfs(1,0);
    cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5024 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 3 ms 5024 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5020 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5024 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 3 ms 5024 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5020 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5036 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 5 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 5 ms 5032 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5168 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 4 ms 5032 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5080 KB Output is correct
36 Correct 3 ms 5036 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5036 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 4 ms 5164 KB Output is correct
41 Correct 3 ms 5204 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5036 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 4 ms 5160 KB Output is correct
46 Correct 4 ms 5052 KB Output is correct
47 Correct 4 ms 5036 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5212 KB Output is correct
50 Correct 4 ms 5164 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5088 KB Output is correct
53 Correct 3 ms 5052 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 4 ms 5040 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5176 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5024 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 3 ms 5024 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5020 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5036 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 5 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 5 ms 5032 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5168 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 4 ms 5032 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5080 KB Output is correct
36 Correct 3 ms 5036 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5036 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 4 ms 5164 KB Output is correct
41 Correct 3 ms 5204 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5036 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 4 ms 5160 KB Output is correct
46 Correct 4 ms 5052 KB Output is correct
47 Correct 4 ms 5036 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5212 KB Output is correct
50 Correct 4 ms 5164 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5088 KB Output is correct
53 Correct 3 ms 5052 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 4 ms 5040 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5176 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 118 ms 16104 KB Output is correct
65 Correct 112 ms 15888 KB Output is correct
66 Correct 127 ms 15916 KB Output is correct
67 Correct 119 ms 15980 KB Output is correct
68 Correct 117 ms 15952 KB Output is correct
69 Correct 110 ms 15940 KB Output is correct
70 Correct 134 ms 15884 KB Output is correct
71 Correct 125 ms 15956 KB Output is correct
72 Correct 113 ms 15968 KB Output is correct
73 Correct 135 ms 31036 KB Output is correct
74 Correct 137 ms 30988 KB Output is correct
75 Correct 144 ms 15864 KB Output is correct
76 Correct 110 ms 15824 KB Output is correct
77 Correct 133 ms 15880 KB Output is correct
78 Correct 127 ms 15844 KB Output is correct
79 Correct 123 ms 15768 KB Output is correct
80 Correct 150 ms 15792 KB Output is correct
81 Correct 88 ms 16304 KB Output is correct
82 Correct 136 ms 16012 KB Output is correct
83 Correct 130 ms 22128 KB Output is correct
84 Correct 131 ms 24668 KB Output is correct
85 Correct 145 ms 24200 KB Output is correct
86 Correct 126 ms 17532 KB Output is correct
87 Correct 108 ms 16792 KB Output is correct
88 Correct 112 ms 17336 KB Output is correct
89 Correct 118 ms 17368 KB Output is correct
90 Correct 107 ms 17100 KB Output is correct
91 Correct 109 ms 17312 KB Output is correct
92 Correct 126 ms 17752 KB Output is correct
93 Correct 116 ms 20708 KB Output is correct
94 Correct 95 ms 22728 KB Output is correct
95 Correct 111 ms 21104 KB Output is correct
96 Correct 138 ms 18932 KB Output is correct
97 Correct 116 ms 17088 KB Output is correct
98 Correct 97 ms 16556 KB Output is correct
99 Correct 119 ms 16316 KB Output is correct
100 Correct 143 ms 20140 KB Output is correct
101 Correct 124 ms 17672 KB Output is correct
102 Correct 126 ms 16728 KB Output is correct
103 Correct 153 ms 16560 KB Output is correct
104 Correct 75 ms 16816 KB Output is correct
105 Correct 129 ms 27280 KB Output is correct
106 Correct 69 ms 16704 KB Output is correct
107 Correct 82 ms 16732 KB Output is correct
108 Correct 132 ms 32028 KB Output is correct
109 Correct 71 ms 16832 KB Output is correct
110 Correct 127 ms 32368 KB Output is correct
111 Correct 101 ms 15772 KB Output is correct