Submission #920291

# Submission time Handle Problem Language Result Execution time Memory
920291 2024-02-02T12:12:21 Z Cookie Power Plant (JOI20_power) C++14
100 / 100
142 ms 75844 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;

#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e6 + 3;
const int mxn = 2e6 + 69, mxq = 1e5 + 5, sq = 500, mxv = 1e6 + 5;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int x[9] = {0, 1, 1, -1, -1, 2, -2, 2, -2};
//const inty[9] = {0, 2, -2, 2, -2, 1, 1, -1, -1};


int n;
vt<int>adj[mxn + 1];
int dp[mxn + 1], sm[mxn + 1], ans = 0;
bool good[mxn + 1];
void dfs(int s, int pre){
    int mx = 0;
    for(auto i: adj[s]){
        if(i != pre){
            dfs(i, s); dp[s] += dp[i]; mx = max(mx, dp[i]);
        }
    }
    if(good[s]){
        dp[s] = max(dp[s] - 1, 1);
        mx++;
    }
    ans = max(ans, max(dp[s], mx));

    //cout << s << " " << dp[s] << "\n";

}
void solve(){
    cin >> n;
    for(int i = 1; i < n; i++){
        int u, v; cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    }
    for(int i = 1; i <= n; i++){
        char c; cin >> c;
        good[i] = (c - '0');
    }
    dfs(1, -1);
    cout << ans;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("COLLEGE.INP", "r", stdin);
    //freopen("COLLEGE.OUT", "w", stdout);
    int tt; tt = 1;
    while(tt--){
        solve();

    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 48216 KB Output is correct
2 Correct 14 ms 48216 KB Output is correct
3 Correct 14 ms 48452 KB Output is correct
4 Correct 14 ms 48220 KB Output is correct
5 Correct 14 ms 48216 KB Output is correct
6 Correct 14 ms 48220 KB Output is correct
7 Correct 14 ms 48216 KB Output is correct
8 Correct 15 ms 48728 KB Output is correct
9 Correct 14 ms 48216 KB Output is correct
10 Correct 14 ms 48376 KB Output is correct
11 Correct 14 ms 48220 KB Output is correct
12 Correct 15 ms 48220 KB Output is correct
13 Correct 15 ms 48220 KB Output is correct
14 Correct 15 ms 48216 KB Output is correct
15 Correct 14 ms 48220 KB Output is correct
16 Correct 14 ms 48444 KB Output is correct
17 Correct 16 ms 48216 KB Output is correct
18 Correct 15 ms 48220 KB Output is correct
19 Correct 16 ms 48728 KB Output is correct
20 Correct 14 ms 48216 KB Output is correct
21 Correct 14 ms 48216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 48216 KB Output is correct
2 Correct 14 ms 48216 KB Output is correct
3 Correct 14 ms 48452 KB Output is correct
4 Correct 14 ms 48220 KB Output is correct
5 Correct 14 ms 48216 KB Output is correct
6 Correct 14 ms 48220 KB Output is correct
7 Correct 14 ms 48216 KB Output is correct
8 Correct 15 ms 48728 KB Output is correct
9 Correct 14 ms 48216 KB Output is correct
10 Correct 14 ms 48376 KB Output is correct
11 Correct 14 ms 48220 KB Output is correct
12 Correct 15 ms 48220 KB Output is correct
13 Correct 15 ms 48220 KB Output is correct
14 Correct 15 ms 48216 KB Output is correct
15 Correct 14 ms 48220 KB Output is correct
16 Correct 14 ms 48444 KB Output is correct
17 Correct 16 ms 48216 KB Output is correct
18 Correct 15 ms 48220 KB Output is correct
19 Correct 16 ms 48728 KB Output is correct
20 Correct 14 ms 48216 KB Output is correct
21 Correct 14 ms 48216 KB Output is correct
22 Correct 16 ms 48472 KB Output is correct
23 Correct 14 ms 48472 KB Output is correct
24 Correct 14 ms 48476 KB Output is correct
25 Correct 14 ms 48472 KB Output is correct
26 Correct 14 ms 48348 KB Output is correct
27 Correct 15 ms 48472 KB Output is correct
28 Correct 15 ms 48472 KB Output is correct
29 Correct 14 ms 48472 KB Output is correct
30 Correct 15 ms 48472 KB Output is correct
31 Correct 15 ms 48460 KB Output is correct
32 Correct 15 ms 48472 KB Output is correct
33 Correct 15 ms 48472 KB Output is correct
34 Correct 15 ms 48472 KB Output is correct
35 Correct 17 ms 48472 KB Output is correct
36 Correct 14 ms 48472 KB Output is correct
37 Correct 15 ms 48476 KB Output is correct
38 Correct 15 ms 48472 KB Output is correct
39 Correct 15 ms 48472 KB Output is correct
40 Correct 15 ms 48472 KB Output is correct
41 Correct 15 ms 48472 KB Output is correct
42 Correct 16 ms 48728 KB Output is correct
43 Correct 15 ms 48472 KB Output is correct
44 Correct 15 ms 48472 KB Output is correct
45 Correct 15 ms 48472 KB Output is correct
46 Correct 15 ms 48472 KB Output is correct
47 Correct 15 ms 48476 KB Output is correct
48 Correct 15 ms 48476 KB Output is correct
49 Correct 15 ms 48472 KB Output is correct
50 Correct 16 ms 48472 KB Output is correct
51 Correct 15 ms 48476 KB Output is correct
52 Correct 15 ms 48472 KB Output is correct
53 Correct 15 ms 48472 KB Output is correct
54 Correct 15 ms 48476 KB Output is correct
55 Correct 15 ms 48476 KB Output is correct
56 Correct 15 ms 48556 KB Output is correct
57 Correct 15 ms 48472 KB Output is correct
58 Correct 15 ms 48472 KB Output is correct
59 Correct 15 ms 48476 KB Output is correct
60 Correct 15 ms 48476 KB Output is correct
61 Correct 15 ms 48472 KB Output is correct
62 Correct 15 ms 48472 KB Output is correct
63 Correct 16 ms 48472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 48216 KB Output is correct
2 Correct 14 ms 48216 KB Output is correct
3 Correct 14 ms 48452 KB Output is correct
4 Correct 14 ms 48220 KB Output is correct
5 Correct 14 ms 48216 KB Output is correct
6 Correct 14 ms 48220 KB Output is correct
7 Correct 14 ms 48216 KB Output is correct
8 Correct 15 ms 48728 KB Output is correct
9 Correct 14 ms 48216 KB Output is correct
10 Correct 14 ms 48376 KB Output is correct
11 Correct 14 ms 48220 KB Output is correct
12 Correct 15 ms 48220 KB Output is correct
13 Correct 15 ms 48220 KB Output is correct
14 Correct 15 ms 48216 KB Output is correct
15 Correct 14 ms 48220 KB Output is correct
16 Correct 14 ms 48444 KB Output is correct
17 Correct 16 ms 48216 KB Output is correct
18 Correct 15 ms 48220 KB Output is correct
19 Correct 16 ms 48728 KB Output is correct
20 Correct 14 ms 48216 KB Output is correct
21 Correct 14 ms 48216 KB Output is correct
22 Correct 16 ms 48472 KB Output is correct
23 Correct 14 ms 48472 KB Output is correct
24 Correct 14 ms 48476 KB Output is correct
25 Correct 14 ms 48472 KB Output is correct
26 Correct 14 ms 48348 KB Output is correct
27 Correct 15 ms 48472 KB Output is correct
28 Correct 15 ms 48472 KB Output is correct
29 Correct 14 ms 48472 KB Output is correct
30 Correct 15 ms 48472 KB Output is correct
31 Correct 15 ms 48460 KB Output is correct
32 Correct 15 ms 48472 KB Output is correct
33 Correct 15 ms 48472 KB Output is correct
34 Correct 15 ms 48472 KB Output is correct
35 Correct 17 ms 48472 KB Output is correct
36 Correct 14 ms 48472 KB Output is correct
37 Correct 15 ms 48476 KB Output is correct
38 Correct 15 ms 48472 KB Output is correct
39 Correct 15 ms 48472 KB Output is correct
40 Correct 15 ms 48472 KB Output is correct
41 Correct 15 ms 48472 KB Output is correct
42 Correct 16 ms 48728 KB Output is correct
43 Correct 15 ms 48472 KB Output is correct
44 Correct 15 ms 48472 KB Output is correct
45 Correct 15 ms 48472 KB Output is correct
46 Correct 15 ms 48472 KB Output is correct
47 Correct 15 ms 48476 KB Output is correct
48 Correct 15 ms 48476 KB Output is correct
49 Correct 15 ms 48472 KB Output is correct
50 Correct 16 ms 48472 KB Output is correct
51 Correct 15 ms 48476 KB Output is correct
52 Correct 15 ms 48472 KB Output is correct
53 Correct 15 ms 48472 KB Output is correct
54 Correct 15 ms 48476 KB Output is correct
55 Correct 15 ms 48476 KB Output is correct
56 Correct 15 ms 48556 KB Output is correct
57 Correct 15 ms 48472 KB Output is correct
58 Correct 15 ms 48472 KB Output is correct
59 Correct 15 ms 48476 KB Output is correct
60 Correct 15 ms 48476 KB Output is correct
61 Correct 15 ms 48472 KB Output is correct
62 Correct 15 ms 48472 KB Output is correct
63 Correct 16 ms 48472 KB Output is correct
64 Correct 104 ms 62288 KB Output is correct
65 Correct 93 ms 62288 KB Output is correct
66 Correct 94 ms 61776 KB Output is correct
67 Correct 95 ms 60436 KB Output is correct
68 Correct 104 ms 60756 KB Output is correct
69 Correct 96 ms 60496 KB Output is correct
70 Correct 90 ms 60552 KB Output is correct
71 Correct 100 ms 62472 KB Output is correct
72 Correct 91 ms 62288 KB Output is correct
73 Correct 110 ms 75088 KB Output is correct
74 Correct 120 ms 75000 KB Output is correct
75 Correct 87 ms 62288 KB Output is correct
76 Correct 90 ms 62544 KB Output is correct
77 Correct 91 ms 62284 KB Output is correct
78 Correct 82 ms 60240 KB Output is correct
79 Correct 91 ms 60420 KB Output is correct
80 Correct 95 ms 62140 KB Output is correct
81 Correct 83 ms 60616 KB Output is correct
82 Correct 92 ms 62508 KB Output is correct
83 Correct 107 ms 65656 KB Output is correct
84 Correct 117 ms 69716 KB Output is correct
85 Correct 125 ms 69372 KB Output is correct
86 Correct 108 ms 63284 KB Output is correct
87 Correct 94 ms 63148 KB Output is correct
88 Correct 98 ms 61520 KB Output is correct
89 Correct 96 ms 63708 KB Output is correct
90 Correct 88 ms 62800 KB Output is correct
91 Correct 92 ms 61776 KB Output is correct
92 Correct 110 ms 63824 KB Output is correct
93 Correct 94 ms 64372 KB Output is correct
94 Correct 95 ms 65944 KB Output is correct
95 Correct 99 ms 64744 KB Output is correct
96 Correct 89 ms 63144 KB Output is correct
97 Correct 97 ms 63536 KB Output is correct
98 Correct 86 ms 61008 KB Output is correct
99 Correct 104 ms 61008 KB Output is correct
100 Correct 92 ms 65872 KB Output is correct
101 Correct 92 ms 63828 KB Output is correct
102 Correct 91 ms 61264 KB Output is correct
103 Correct 98 ms 62800 KB Output is correct
104 Correct 67 ms 62404 KB Output is correct
105 Correct 142 ms 70164 KB Output is correct
106 Correct 67 ms 61124 KB Output is correct
107 Correct 70 ms 62404 KB Output is correct
108 Correct 118 ms 75844 KB Output is correct
109 Correct 68 ms 60420 KB Output is correct
110 Correct 121 ms 75412 KB Output is correct
111 Correct 79 ms 61776 KB Output is correct