Submission #715180

# Submission time Handle Problem Language Result Execution time Memory
715180 2023-03-26T07:19:03 Z fdnfksd Power Plant (JOI20_power) C++14
100 / 100
179 ms 29908 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll ans=0;
vector<ll>g[maxN];
ll dp[maxN];
string s;
void dfs(ll u=1,ll p=0)
{
    dp[u]=(s[u]=='1');
    ll x=0;
    for(int v:g[u])
    {
        if(v!=p)
        {
            dfs(v,u);
            x+=dp[v];
            //dp[u]=max(dp[u],dp[v]);
        }
    }
    dp[u]=max(dp[u],x-(s[u]=='1'));
    ans=max(ans,dp[u]);
    for(int v:g[u])
    {
        if(v!=p)
        {
            ans=max(ans,dp[v]+(s[u]=='1'));
        }
    }
}
ll n;
void solve()
{
    cin >> n;
    for(int i=1;i<n;i++)
    {
        ll u,v;
        cin >> u >> v ;
        g[u].pb(v);
        g[v].pb(u);
    }
    cin >> s;
    s=' '+s;
    dfs();
    cout << ans;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7328 KB Output is correct
10 Correct 5 ms 7252 KB Output is correct
11 Correct 4 ms 7252 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7368 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 4 ms 7252 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7328 KB Output is correct
10 Correct 5 ms 7252 KB Output is correct
11 Correct 4 ms 7252 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7368 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 4 ms 7252 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 4 ms 7252 KB Output is correct
22 Correct 4 ms 7424 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 5 ms 7380 KB Output is correct
25 Correct 5 ms 7380 KB Output is correct
26 Correct 5 ms 7384 KB Output is correct
27 Correct 5 ms 7380 KB Output is correct
28 Correct 6 ms 7380 KB Output is correct
29 Correct 5 ms 7508 KB Output is correct
30 Correct 5 ms 7508 KB Output is correct
31 Correct 6 ms 7380 KB Output is correct
32 Correct 5 ms 7384 KB Output is correct
33 Correct 5 ms 7380 KB Output is correct
34 Correct 5 ms 7380 KB Output is correct
35 Correct 5 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 5 ms 7380 KB Output is correct
38 Correct 5 ms 7384 KB Output is correct
39 Correct 5 ms 7508 KB Output is correct
40 Correct 5 ms 7508 KB Output is correct
41 Correct 6 ms 7508 KB Output is correct
42 Correct 5 ms 7496 KB Output is correct
43 Correct 6 ms 7380 KB Output is correct
44 Correct 6 ms 7508 KB Output is correct
45 Correct 5 ms 7508 KB Output is correct
46 Correct 5 ms 7380 KB Output is correct
47 Correct 5 ms 7464 KB Output is correct
48 Correct 4 ms 7508 KB Output is correct
49 Correct 5 ms 7508 KB Output is correct
50 Correct 4 ms 7432 KB Output is correct
51 Correct 5 ms 7508 KB Output is correct
52 Correct 4 ms 7380 KB Output is correct
53 Correct 4 ms 7508 KB Output is correct
54 Correct 4 ms 7432 KB Output is correct
55 Correct 5 ms 7384 KB Output is correct
56 Correct 6 ms 7384 KB Output is correct
57 Correct 7 ms 7516 KB Output is correct
58 Correct 5 ms 7492 KB Output is correct
59 Correct 5 ms 7436 KB Output is correct
60 Correct 7 ms 7508 KB Output is correct
61 Correct 5 ms 7388 KB Output is correct
62 Correct 5 ms 7508 KB Output is correct
63 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7328 KB Output is correct
10 Correct 5 ms 7252 KB Output is correct
11 Correct 4 ms 7252 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7368 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 4 ms 7252 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 4 ms 7252 KB Output is correct
22 Correct 4 ms 7424 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 5 ms 7380 KB Output is correct
25 Correct 5 ms 7380 KB Output is correct
26 Correct 5 ms 7384 KB Output is correct
27 Correct 5 ms 7380 KB Output is correct
28 Correct 6 ms 7380 KB Output is correct
29 Correct 5 ms 7508 KB Output is correct
30 Correct 5 ms 7508 KB Output is correct
31 Correct 6 ms 7380 KB Output is correct
32 Correct 5 ms 7384 KB Output is correct
33 Correct 5 ms 7380 KB Output is correct
34 Correct 5 ms 7380 KB Output is correct
35 Correct 5 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 5 ms 7380 KB Output is correct
38 Correct 5 ms 7384 KB Output is correct
39 Correct 5 ms 7508 KB Output is correct
40 Correct 5 ms 7508 KB Output is correct
41 Correct 6 ms 7508 KB Output is correct
42 Correct 5 ms 7496 KB Output is correct
43 Correct 6 ms 7380 KB Output is correct
44 Correct 6 ms 7508 KB Output is correct
45 Correct 5 ms 7508 KB Output is correct
46 Correct 5 ms 7380 KB Output is correct
47 Correct 5 ms 7464 KB Output is correct
48 Correct 4 ms 7508 KB Output is correct
49 Correct 5 ms 7508 KB Output is correct
50 Correct 4 ms 7432 KB Output is correct
51 Correct 5 ms 7508 KB Output is correct
52 Correct 4 ms 7380 KB Output is correct
53 Correct 4 ms 7508 KB Output is correct
54 Correct 4 ms 7432 KB Output is correct
55 Correct 5 ms 7384 KB Output is correct
56 Correct 6 ms 7384 KB Output is correct
57 Correct 7 ms 7516 KB Output is correct
58 Correct 5 ms 7492 KB Output is correct
59 Correct 5 ms 7436 KB Output is correct
60 Correct 7 ms 7508 KB Output is correct
61 Correct 5 ms 7388 KB Output is correct
62 Correct 5 ms 7508 KB Output is correct
63 Correct 4 ms 7380 KB Output is correct
64 Correct 153 ms 17260 KB Output is correct
65 Correct 173 ms 17152 KB Output is correct
66 Correct 135 ms 17256 KB Output is correct
67 Correct 133 ms 17144 KB Output is correct
68 Correct 125 ms 17136 KB Output is correct
69 Correct 162 ms 17168 KB Output is correct
70 Correct 119 ms 17196 KB Output is correct
71 Correct 141 ms 17364 KB Output is correct
72 Correct 133 ms 17200 KB Output is correct
73 Correct 163 ms 28924 KB Output is correct
74 Correct 179 ms 28912 KB Output is correct
75 Correct 132 ms 18440 KB Output is correct
76 Correct 126 ms 18464 KB Output is correct
77 Correct 161 ms 17196 KB Output is correct
78 Correct 145 ms 17168 KB Output is correct
79 Correct 145 ms 17176 KB Output is correct
80 Correct 152 ms 17344 KB Output is correct
81 Correct 113 ms 17340 KB Output is correct
82 Correct 131 ms 17104 KB Output is correct
83 Correct 157 ms 22288 KB Output is correct
84 Correct 154 ms 24400 KB Output is correct
85 Correct 148 ms 24156 KB Output is correct
86 Correct 127 ms 18572 KB Output is correct
87 Correct 138 ms 17936 KB Output is correct
88 Correct 129 ms 18076 KB Output is correct
89 Correct 137 ms 18048 KB Output is correct
90 Correct 108 ms 17908 KB Output is correct
91 Correct 142 ms 18132 KB Output is correct
92 Correct 141 ms 18452 KB Output is correct
93 Correct 120 ms 20760 KB Output is correct
94 Correct 123 ms 22456 KB Output is correct
95 Correct 127 ms 20908 KB Output is correct
96 Correct 129 ms 19160 KB Output is correct
97 Correct 133 ms 17752 KB Output is correct
98 Correct 133 ms 17412 KB Output is correct
99 Correct 127 ms 17228 KB Output is correct
100 Correct 110 ms 20240 KB Output is correct
101 Correct 139 ms 18124 KB Output is correct
102 Correct 129 ms 17516 KB Output is correct
103 Correct 147 ms 17644 KB Output is correct
104 Correct 86 ms 17768 KB Output is correct
105 Correct 152 ms 25724 KB Output is correct
106 Correct 83 ms 17888 KB Output is correct
107 Correct 75 ms 17908 KB Output is correct
108 Correct 162 ms 29520 KB Output is correct
109 Correct 79 ms 17752 KB Output is correct
110 Correct 149 ms 29908 KB Output is correct
111 Correct 115 ms 17160 KB Output is correct