Submission #1083098

# Submission time Handle Problem Language Result Execution time Memory
1083098 2024-09-02T14:07:20 Z Tymond Power Plant (JOI20_power) C++17
100 / 100
71 ms 31636 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int MAXN = 2e5 + 7;
vi g[MAXN];
int dp[MAXN];
string s;
int n;
int ans = 1;

void dfs(int v, int p){
    dp[v] = (s[v - 1] - '0');
    ans = max(ans, dp[v]);
    int sum = 0;
    int mx = 0;
    for(auto u : g[v]){
        if(u != p){
            dfs(u, v);
            mx = max(mx, dp[u]);
            if(s[v - 1] == '0'){
                dp[v] += dp[u];
            }else{
                sum += dp[u];
            }
        }
    }

    if(s[v - 1] == '1'){
        dp[v] = max(1, sum - 1);
        ans = max(ans, mx + 1);
    }
    //cout << v << ' ' << dp[v] << '\n';
    ans = max(ans, dp[v]);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    cin >> s;
    ans = 1;
    dfs(1, 1);
    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 2 ms 5772 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5568 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5772 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5772 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5668 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5740 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 3 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 2 ms 5772 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5568 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5772 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5772 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5668 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5740 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 3 ms 5724 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5728 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 2 ms 5976 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 2 ms 5724 KB Output is correct
32 Correct 2 ms 5724 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 2 ms 5724 KB Output is correct
35 Correct 3 ms 5784 KB Output is correct
36 Correct 2 ms 5724 KB Output is correct
37 Correct 2 ms 5724 KB Output is correct
38 Correct 3 ms 5724 KB Output is correct
39 Correct 3 ms 5724 KB Output is correct
40 Correct 2 ms 5728 KB Output is correct
41 Correct 2 ms 5724 KB Output is correct
42 Correct 2 ms 5724 KB Output is correct
43 Correct 2 ms 5724 KB Output is correct
44 Correct 2 ms 5724 KB Output is correct
45 Correct 2 ms 5720 KB Output is correct
46 Correct 2 ms 5648 KB Output is correct
47 Correct 2 ms 5724 KB Output is correct
48 Correct 2 ms 5724 KB Output is correct
49 Correct 2 ms 5724 KB Output is correct
50 Correct 2 ms 5724 KB Output is correct
51 Correct 2 ms 5976 KB Output is correct
52 Correct 2 ms 5724 KB Output is correct
53 Correct 2 ms 5980 KB Output is correct
54 Correct 2 ms 5724 KB Output is correct
55 Correct 3 ms 5724 KB Output is correct
56 Correct 2 ms 5724 KB Output is correct
57 Correct 3 ms 5980 KB Output is correct
58 Correct 3 ms 5724 KB Output is correct
59 Correct 2 ms 5724 KB Output is correct
60 Correct 2 ms 5724 KB Output is correct
61 Correct 2 ms 5724 KB Output is correct
62 Correct 2 ms 5784 KB Output is correct
63 Correct 3 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 2 ms 5772 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5568 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5772 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5772 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5668 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5740 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 3 ms 5724 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5728 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 2 ms 5976 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 2 ms 5724 KB Output is correct
32 Correct 2 ms 5724 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 2 ms 5724 KB Output is correct
35 Correct 3 ms 5784 KB Output is correct
36 Correct 2 ms 5724 KB Output is correct
37 Correct 2 ms 5724 KB Output is correct
38 Correct 3 ms 5724 KB Output is correct
39 Correct 3 ms 5724 KB Output is correct
40 Correct 2 ms 5728 KB Output is correct
41 Correct 2 ms 5724 KB Output is correct
42 Correct 2 ms 5724 KB Output is correct
43 Correct 2 ms 5724 KB Output is correct
44 Correct 2 ms 5724 KB Output is correct
45 Correct 2 ms 5720 KB Output is correct
46 Correct 2 ms 5648 KB Output is correct
47 Correct 2 ms 5724 KB Output is correct
48 Correct 2 ms 5724 KB Output is correct
49 Correct 2 ms 5724 KB Output is correct
50 Correct 2 ms 5724 KB Output is correct
51 Correct 2 ms 5976 KB Output is correct
52 Correct 2 ms 5724 KB Output is correct
53 Correct 2 ms 5980 KB Output is correct
54 Correct 2 ms 5724 KB Output is correct
55 Correct 3 ms 5724 KB Output is correct
56 Correct 2 ms 5724 KB Output is correct
57 Correct 3 ms 5980 KB Output is correct
58 Correct 3 ms 5724 KB Output is correct
59 Correct 2 ms 5724 KB Output is correct
60 Correct 2 ms 5724 KB Output is correct
61 Correct 2 ms 5724 KB Output is correct
62 Correct 2 ms 5784 KB Output is correct
63 Correct 3 ms 5724 KB Output is correct
64 Correct 65 ms 15292 KB Output is correct
65 Correct 50 ms 15248 KB Output is correct
66 Correct 65 ms 15232 KB Output is correct
67 Correct 57 ms 15248 KB Output is correct
68 Correct 51 ms 15228 KB Output is correct
69 Correct 52 ms 15244 KB Output is correct
70 Correct 62 ms 15264 KB Output is correct
71 Correct 50 ms 15260 KB Output is correct
72 Correct 54 ms 15332 KB Output is correct
73 Correct 71 ms 30352 KB Output is correct
74 Correct 62 ms 30352 KB Output is correct
75 Correct 52 ms 15156 KB Output is correct
76 Correct 51 ms 15164 KB Output is correct
77 Correct 55 ms 15208 KB Output is correct
78 Correct 51 ms 15048 KB Output is correct
79 Correct 49 ms 15164 KB Output is correct
80 Correct 50 ms 15156 KB Output is correct
81 Correct 48 ms 15564 KB Output is correct
82 Correct 48 ms 15312 KB Output is correct
83 Correct 55 ms 21400 KB Output is correct
84 Correct 61 ms 24012 KB Output is correct
85 Correct 57 ms 23452 KB Output is correct
86 Correct 56 ms 16788 KB Output is correct
87 Correct 51 ms 16016 KB Output is correct
88 Correct 57 ms 16584 KB Output is correct
89 Correct 51 ms 16520 KB Output is correct
90 Correct 61 ms 16344 KB Output is correct
91 Correct 54 ms 16556 KB Output is correct
92 Correct 54 ms 16908 KB Output is correct
93 Correct 51 ms 19812 KB Output is correct
94 Correct 52 ms 22068 KB Output is correct
95 Correct 51 ms 20300 KB Output is correct
96 Correct 59 ms 18176 KB Output is correct
97 Correct 50 ms 16476 KB Output is correct
98 Correct 52 ms 15784 KB Output is correct
99 Correct 47 ms 15508 KB Output is correct
100 Correct 54 ms 19328 KB Output is correct
101 Correct 58 ms 16912 KB Output is correct
102 Correct 49 ms 16136 KB Output is correct
103 Correct 57 ms 15852 KB Output is correct
104 Correct 36 ms 16068 KB Output is correct
105 Correct 55 ms 26512 KB Output is correct
106 Correct 36 ms 16068 KB Output is correct
107 Correct 36 ms 16068 KB Output is correct
108 Correct 59 ms 31376 KB Output is correct
109 Correct 38 ms 16068 KB Output is correct
110 Correct 61 ms 31636 KB Output is correct
111 Correct 45 ms 15172 KB Output is correct