Submission #1098222

# Submission time Handle Problem Language Result Execution time Memory
1098222 2024-10-09T06:34:40 Z Sputnik123 Power Plant (JOI20_power) C++17
100 / 100
145 ms 142540 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define in insert
#define pll pair<ll,ll>
#define vpl vector<pll>
#define vll vector <ll>
#define vl vector<ll>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()
#define endl "\n"
#define ull unsigned long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt,fma")
const ll sz = 5e6 + 5;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll eps = 1e-12;
const ll P1 = 31; // for hashing
const ll P2 = 41; // for hashing 
//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// ll idx = 1;
ll n, ans, dp[sz];
vll g[sz];
string s;
void dfs(ll node, ll par = -1)
{
    ll sum = 0, mx = 0;
    ll is = (s[node] == '1');
    for(ll i : g[node])
    {
        if(i == par)
            continue;
        dfs(i, node);
        sum += dp[i];
        mx = max(mx, dp[i]);
    }
    dp[node] = max(is, sum - is);
    ans = max({ans, sum - is, mx + is});
}
void solve()
{   
    cin >> n;
    for(ll i = 1; i < n; i++){
        ll u,  v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    cin >> s;
    s = '!' + s;
    dfs(1);
    cout << ans << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    long long t = 1;
    // cin >> t;
    while(t--)
    {	   
        // cout << "Case #" << (int) idx <<": ";
        solve();
        // idx++;
    }
}
/* 
Note : don`t use fast input in interactive questions
Note : Compare long double with eps = 1e-12
Note : Always write 2 hashes
*/
# Verdict Execution time Memory Grader output
1 Correct 52 ms 117840 KB Output is correct
2 Correct 51 ms 117800 KB Output is correct
3 Correct 44 ms 117764 KB Output is correct
4 Correct 43 ms 117844 KB Output is correct
5 Correct 49 ms 117840 KB Output is correct
6 Correct 48 ms 117684 KB Output is correct
7 Correct 46 ms 117844 KB Output is correct
8 Correct 49 ms 117660 KB Output is correct
9 Correct 51 ms 117840 KB Output is correct
10 Correct 50 ms 117844 KB Output is correct
11 Correct 50 ms 117844 KB Output is correct
12 Correct 47 ms 117716 KB Output is correct
13 Correct 49 ms 117784 KB Output is correct
14 Correct 50 ms 117840 KB Output is correct
15 Correct 49 ms 117840 KB Output is correct
16 Correct 50 ms 117656 KB Output is correct
17 Correct 49 ms 117840 KB Output is correct
18 Correct 49 ms 117628 KB Output is correct
19 Correct 60 ms 117668 KB Output is correct
20 Correct 46 ms 117740 KB Output is correct
21 Correct 46 ms 117852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 117840 KB Output is correct
2 Correct 51 ms 117800 KB Output is correct
3 Correct 44 ms 117764 KB Output is correct
4 Correct 43 ms 117844 KB Output is correct
5 Correct 49 ms 117840 KB Output is correct
6 Correct 48 ms 117684 KB Output is correct
7 Correct 46 ms 117844 KB Output is correct
8 Correct 49 ms 117660 KB Output is correct
9 Correct 51 ms 117840 KB Output is correct
10 Correct 50 ms 117844 KB Output is correct
11 Correct 50 ms 117844 KB Output is correct
12 Correct 47 ms 117716 KB Output is correct
13 Correct 49 ms 117784 KB Output is correct
14 Correct 50 ms 117840 KB Output is correct
15 Correct 49 ms 117840 KB Output is correct
16 Correct 50 ms 117656 KB Output is correct
17 Correct 49 ms 117840 KB Output is correct
18 Correct 49 ms 117628 KB Output is correct
19 Correct 60 ms 117668 KB Output is correct
20 Correct 46 ms 117740 KB Output is correct
21 Correct 46 ms 117852 KB Output is correct
22 Correct 51 ms 117736 KB Output is correct
23 Correct 49 ms 117840 KB Output is correct
24 Correct 48 ms 117828 KB Output is correct
25 Correct 46 ms 117840 KB Output is correct
26 Correct 50 ms 117844 KB Output is correct
27 Correct 54 ms 117844 KB Output is correct
28 Correct 54 ms 117828 KB Output is correct
29 Correct 49 ms 118096 KB Output is correct
30 Correct 47 ms 117840 KB Output is correct
31 Correct 50 ms 117840 KB Output is correct
32 Correct 50 ms 117840 KB Output is correct
33 Correct 46 ms 117956 KB Output is correct
34 Correct 44 ms 117840 KB Output is correct
35 Correct 49 ms 117840 KB Output is correct
36 Correct 47 ms 117852 KB Output is correct
37 Correct 46 ms 117844 KB Output is correct
38 Correct 48 ms 117848 KB Output is correct
39 Correct 50 ms 117844 KB Output is correct
40 Correct 50 ms 117844 KB Output is correct
41 Correct 52 ms 117844 KB Output is correct
42 Correct 45 ms 117840 KB Output is correct
43 Correct 50 ms 117844 KB Output is correct
44 Correct 52 ms 117840 KB Output is correct
45 Correct 50 ms 117840 KB Output is correct
46 Correct 49 ms 117780 KB Output is correct
47 Correct 55 ms 117980 KB Output is correct
48 Correct 47 ms 117952 KB Output is correct
49 Correct 45 ms 117848 KB Output is correct
50 Correct 44 ms 117940 KB Output is correct
51 Correct 77 ms 117840 KB Output is correct
52 Correct 46 ms 117872 KB Output is correct
53 Correct 61 ms 117840 KB Output is correct
54 Correct 72 ms 117844 KB Output is correct
55 Correct 46 ms 117840 KB Output is correct
56 Correct 50 ms 117864 KB Output is correct
57 Correct 45 ms 117912 KB Output is correct
58 Correct 49 ms 117800 KB Output is correct
59 Correct 47 ms 117752 KB Output is correct
60 Correct 48 ms 117852 KB Output is correct
61 Correct 55 ms 117904 KB Output is correct
62 Correct 49 ms 117852 KB Output is correct
63 Correct 54 ms 117984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 117840 KB Output is correct
2 Correct 51 ms 117800 KB Output is correct
3 Correct 44 ms 117764 KB Output is correct
4 Correct 43 ms 117844 KB Output is correct
5 Correct 49 ms 117840 KB Output is correct
6 Correct 48 ms 117684 KB Output is correct
7 Correct 46 ms 117844 KB Output is correct
8 Correct 49 ms 117660 KB Output is correct
9 Correct 51 ms 117840 KB Output is correct
10 Correct 50 ms 117844 KB Output is correct
11 Correct 50 ms 117844 KB Output is correct
12 Correct 47 ms 117716 KB Output is correct
13 Correct 49 ms 117784 KB Output is correct
14 Correct 50 ms 117840 KB Output is correct
15 Correct 49 ms 117840 KB Output is correct
16 Correct 50 ms 117656 KB Output is correct
17 Correct 49 ms 117840 KB Output is correct
18 Correct 49 ms 117628 KB Output is correct
19 Correct 60 ms 117668 KB Output is correct
20 Correct 46 ms 117740 KB Output is correct
21 Correct 46 ms 117852 KB Output is correct
22 Correct 51 ms 117736 KB Output is correct
23 Correct 49 ms 117840 KB Output is correct
24 Correct 48 ms 117828 KB Output is correct
25 Correct 46 ms 117840 KB Output is correct
26 Correct 50 ms 117844 KB Output is correct
27 Correct 54 ms 117844 KB Output is correct
28 Correct 54 ms 117828 KB Output is correct
29 Correct 49 ms 118096 KB Output is correct
30 Correct 47 ms 117840 KB Output is correct
31 Correct 50 ms 117840 KB Output is correct
32 Correct 50 ms 117840 KB Output is correct
33 Correct 46 ms 117956 KB Output is correct
34 Correct 44 ms 117840 KB Output is correct
35 Correct 49 ms 117840 KB Output is correct
36 Correct 47 ms 117852 KB Output is correct
37 Correct 46 ms 117844 KB Output is correct
38 Correct 48 ms 117848 KB Output is correct
39 Correct 50 ms 117844 KB Output is correct
40 Correct 50 ms 117844 KB Output is correct
41 Correct 52 ms 117844 KB Output is correct
42 Correct 45 ms 117840 KB Output is correct
43 Correct 50 ms 117844 KB Output is correct
44 Correct 52 ms 117840 KB Output is correct
45 Correct 50 ms 117840 KB Output is correct
46 Correct 49 ms 117780 KB Output is correct
47 Correct 55 ms 117980 KB Output is correct
48 Correct 47 ms 117952 KB Output is correct
49 Correct 45 ms 117848 KB Output is correct
50 Correct 44 ms 117940 KB Output is correct
51 Correct 77 ms 117840 KB Output is correct
52 Correct 46 ms 117872 KB Output is correct
53 Correct 61 ms 117840 KB Output is correct
54 Correct 72 ms 117844 KB Output is correct
55 Correct 46 ms 117840 KB Output is correct
56 Correct 50 ms 117864 KB Output is correct
57 Correct 45 ms 117912 KB Output is correct
58 Correct 49 ms 117800 KB Output is correct
59 Correct 47 ms 117752 KB Output is correct
60 Correct 48 ms 117852 KB Output is correct
61 Correct 55 ms 117904 KB Output is correct
62 Correct 49 ms 117852 KB Output is correct
63 Correct 54 ms 117984 KB Output is correct
64 Correct 135 ms 126920 KB Output is correct
65 Correct 108 ms 127072 KB Output is correct
66 Correct 117 ms 127088 KB Output is correct
67 Correct 145 ms 126924 KB Output is correct
68 Correct 115 ms 126908 KB Output is correct
69 Correct 112 ms 126880 KB Output is correct
70 Correct 105 ms 126944 KB Output is correct
71 Correct 107 ms 126944 KB Output is correct
72 Correct 111 ms 126988 KB Output is correct
73 Correct 118 ms 141264 KB Output is correct
74 Correct 117 ms 141076 KB Output is correct
75 Correct 114 ms 128204 KB Output is correct
76 Correct 111 ms 128208 KB Output is correct
77 Correct 108 ms 126920 KB Output is correct
78 Correct 111 ms 126928 KB Output is correct
79 Correct 109 ms 126888 KB Output is correct
80 Correct 109 ms 126920 KB Output is correct
81 Correct 102 ms 127176 KB Output is correct
82 Correct 104 ms 126724 KB Output is correct
83 Correct 113 ms 133072 KB Output is correct
84 Correct 118 ms 135664 KB Output is correct
85 Correct 117 ms 135384 KB Output is correct
86 Correct 110 ms 128608 KB Output is correct
87 Correct 105 ms 127784 KB Output is correct
88 Correct 112 ms 128008 KB Output is correct
89 Correct 110 ms 127964 KB Output is correct
90 Correct 110 ms 127780 KB Output is correct
91 Correct 106 ms 127924 KB Output is correct
92 Correct 116 ms 128540 KB Output is correct
93 Correct 108 ms 131272 KB Output is correct
94 Correct 100 ms 133312 KB Output is correct
95 Correct 98 ms 131580 KB Output is correct
96 Correct 107 ms 129352 KB Output is correct
97 Correct 102 ms 127788 KB Output is correct
98 Correct 97 ms 127072 KB Output is correct
99 Correct 102 ms 127096 KB Output is correct
100 Correct 105 ms 130736 KB Output is correct
101 Correct 106 ms 128072 KB Output is correct
102 Correct 98 ms 127388 KB Output is correct
103 Correct 100 ms 127332 KB Output is correct
104 Correct 88 ms 127428 KB Output is correct
105 Correct 110 ms 137420 KB Output is correct
106 Correct 87 ms 127700 KB Output is correct
107 Correct 84 ms 127712 KB Output is correct
108 Correct 121 ms 142032 KB Output is correct
109 Correct 92 ms 127680 KB Output is correct
110 Correct 143 ms 142540 KB Output is correct
111 Correct 106 ms 126940 KB Output is correct