Submission #920290

# Submission time Handle Problem Language Result Execution time Memory
920290 2024-02-02T12:11:06 Z Cookie Power Plant (JOI20_power) C++14
0 / 100
16 ms 48728 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] += max(sm[i] - good[i], dp[i]); sm[s] += dp[i]; mx = max(mx, dp[i]);
        }
    }
    if(good[s]){
        dp[s] = max(dp[s] - 1, 1);

    }
    ans = max(ans, max(dp[s], mx + 1));

    //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 14 ms 48216 KB Output is correct
2 Correct 14 ms 48216 KB Output is correct
3 Correct 14 ms 48216 KB Output is correct
4 Correct 15 ms 48216 KB Output is correct
5 Correct 14 ms 48216 KB Output is correct
6 Correct 14 ms 48216 KB Output is correct
7 Correct 14 ms 48216 KB Output is correct
8 Correct 14 ms 48216 KB Output is correct
9 Correct 14 ms 48216 KB Output is correct
10 Correct 15 ms 48216 KB Output is correct
11 Correct 13 ms 48216 KB Output is correct
12 Correct 14 ms 48216 KB Output is correct
13 Correct 14 ms 48216 KB Output is correct
14 Correct 14 ms 48216 KB Output is correct
15 Incorrect 16 ms 48728 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 48216 KB Output is correct
2 Correct 14 ms 48216 KB Output is correct
3 Correct 14 ms 48216 KB Output is correct
4 Correct 15 ms 48216 KB Output is correct
5 Correct 14 ms 48216 KB Output is correct
6 Correct 14 ms 48216 KB Output is correct
7 Correct 14 ms 48216 KB Output is correct
8 Correct 14 ms 48216 KB Output is correct
9 Correct 14 ms 48216 KB Output is correct
10 Correct 15 ms 48216 KB Output is correct
11 Correct 13 ms 48216 KB Output is correct
12 Correct 14 ms 48216 KB Output is correct
13 Correct 14 ms 48216 KB Output is correct
14 Correct 14 ms 48216 KB Output is correct
15 Incorrect 16 ms 48728 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 48216 KB Output is correct
2 Correct 14 ms 48216 KB Output is correct
3 Correct 14 ms 48216 KB Output is correct
4 Correct 15 ms 48216 KB Output is correct
5 Correct 14 ms 48216 KB Output is correct
6 Correct 14 ms 48216 KB Output is correct
7 Correct 14 ms 48216 KB Output is correct
8 Correct 14 ms 48216 KB Output is correct
9 Correct 14 ms 48216 KB Output is correct
10 Correct 15 ms 48216 KB Output is correct
11 Correct 13 ms 48216 KB Output is correct
12 Correct 14 ms 48216 KB Output is correct
13 Correct 14 ms 48216 KB Output is correct
14 Correct 14 ms 48216 KB Output is correct
15 Incorrect 16 ms 48728 KB Output isn't correct
16 Halted 0 ms 0 KB -