Submission #660864

# Submission time Handle Problem Language Result Execution time Memory
660864 2022-11-23T10:59:24 Z Danilo21 Power Plant (JOI20_power) C++14
100 / 100
168 ms 51212 KB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 4e18;
const int mxN = 1e6+10, INF = 2e9;
int n, m, gen[mxN], dp[mxN];
vector<int> g[mxN];

int dfs(int s = 0, int p = -1){

    int sum = 0, mx = 0, ans = 0;
    for (int u : g[s]){
        if (u^p){
            smax(ans, dfs(u, s));
            sum += dp[u];
            smax(mx, dp[u]);
        }
    }
    dp[s] = max(sum - gen[s], gen[s]);
    return max(ans, max(mx + gen[s], dp[s]));
}

void Solve(){

    cin >> n;
    for (int i = 1; i < n; i++){
        ri(u); ri(v);
        u--; v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    rs(s);
    for (int i = 0; i < n; i++)
        gen[i] = (int)(s[i] - '0');
    cout << dfs() << en;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 14 ms 23744 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 15 ms 23824 KB Output is correct
7 Correct 18 ms 23820 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 14 ms 23780 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 12 ms 23820 KB Output is correct
12 Correct 12 ms 23788 KB Output is correct
13 Correct 13 ms 23808 KB Output is correct
14 Correct 14 ms 23764 KB Output is correct
15 Correct 12 ms 23832 KB Output is correct
16 Correct 13 ms 23824 KB Output is correct
17 Correct 14 ms 23712 KB Output is correct
18 Correct 14 ms 23768 KB Output is correct
19 Correct 14 ms 23764 KB Output is correct
20 Correct 13 ms 23820 KB Output is correct
21 Correct 14 ms 23824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 14 ms 23744 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 15 ms 23824 KB Output is correct
7 Correct 18 ms 23820 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 14 ms 23780 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 12 ms 23820 KB Output is correct
12 Correct 12 ms 23788 KB Output is correct
13 Correct 13 ms 23808 KB Output is correct
14 Correct 14 ms 23764 KB Output is correct
15 Correct 12 ms 23832 KB Output is correct
16 Correct 13 ms 23824 KB Output is correct
17 Correct 14 ms 23712 KB Output is correct
18 Correct 14 ms 23768 KB Output is correct
19 Correct 14 ms 23764 KB Output is correct
20 Correct 13 ms 23820 KB Output is correct
21 Correct 14 ms 23824 KB Output is correct
22 Correct 16 ms 23876 KB Output is correct
23 Correct 14 ms 23828 KB Output is correct
24 Correct 14 ms 23832 KB Output is correct
25 Correct 14 ms 23892 KB Output is correct
26 Correct 12 ms 23932 KB Output is correct
27 Correct 15 ms 23832 KB Output is correct
28 Correct 14 ms 23832 KB Output is correct
29 Correct 14 ms 24020 KB Output is correct
30 Correct 13 ms 24020 KB Output is correct
31 Correct 16 ms 23836 KB Output is correct
32 Correct 16 ms 23804 KB Output is correct
33 Correct 14 ms 23832 KB Output is correct
34 Correct 14 ms 23896 KB Output is correct
35 Correct 12 ms 23916 KB Output is correct
36 Correct 14 ms 23892 KB Output is correct
37 Correct 15 ms 23880 KB Output is correct
38 Correct 14 ms 23892 KB Output is correct
39 Correct 12 ms 23928 KB Output is correct
40 Correct 16 ms 23936 KB Output is correct
41 Correct 15 ms 23960 KB Output is correct
42 Correct 12 ms 23896 KB Output is correct
43 Correct 15 ms 23916 KB Output is correct
44 Correct 12 ms 23892 KB Output is correct
45 Correct 14 ms 23876 KB Output is correct
46 Correct 16 ms 23944 KB Output is correct
47 Correct 13 ms 23892 KB Output is correct
48 Correct 13 ms 23952 KB Output is correct
49 Correct 12 ms 23952 KB Output is correct
50 Correct 12 ms 23892 KB Output is correct
51 Correct 12 ms 23880 KB Output is correct
52 Correct 15 ms 23920 KB Output is correct
53 Correct 13 ms 23892 KB Output is correct
54 Correct 12 ms 23892 KB Output is correct
55 Correct 13 ms 23832 KB Output is correct
56 Correct 16 ms 23912 KB Output is correct
57 Correct 15 ms 24068 KB Output is correct
58 Correct 13 ms 23892 KB Output is correct
59 Correct 12 ms 23876 KB Output is correct
60 Correct 15 ms 23884 KB Output is correct
61 Correct 12 ms 23828 KB Output is correct
62 Correct 13 ms 23968 KB Output is correct
63 Correct 12 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 14 ms 23744 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 15 ms 23824 KB Output is correct
7 Correct 18 ms 23820 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 14 ms 23780 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 12 ms 23820 KB Output is correct
12 Correct 12 ms 23788 KB Output is correct
13 Correct 13 ms 23808 KB Output is correct
14 Correct 14 ms 23764 KB Output is correct
15 Correct 12 ms 23832 KB Output is correct
16 Correct 13 ms 23824 KB Output is correct
17 Correct 14 ms 23712 KB Output is correct
18 Correct 14 ms 23768 KB Output is correct
19 Correct 14 ms 23764 KB Output is correct
20 Correct 13 ms 23820 KB Output is correct
21 Correct 14 ms 23824 KB Output is correct
22 Correct 16 ms 23876 KB Output is correct
23 Correct 14 ms 23828 KB Output is correct
24 Correct 14 ms 23832 KB Output is correct
25 Correct 14 ms 23892 KB Output is correct
26 Correct 12 ms 23932 KB Output is correct
27 Correct 15 ms 23832 KB Output is correct
28 Correct 14 ms 23832 KB Output is correct
29 Correct 14 ms 24020 KB Output is correct
30 Correct 13 ms 24020 KB Output is correct
31 Correct 16 ms 23836 KB Output is correct
32 Correct 16 ms 23804 KB Output is correct
33 Correct 14 ms 23832 KB Output is correct
34 Correct 14 ms 23896 KB Output is correct
35 Correct 12 ms 23916 KB Output is correct
36 Correct 14 ms 23892 KB Output is correct
37 Correct 15 ms 23880 KB Output is correct
38 Correct 14 ms 23892 KB Output is correct
39 Correct 12 ms 23928 KB Output is correct
40 Correct 16 ms 23936 KB Output is correct
41 Correct 15 ms 23960 KB Output is correct
42 Correct 12 ms 23896 KB Output is correct
43 Correct 15 ms 23916 KB Output is correct
44 Correct 12 ms 23892 KB Output is correct
45 Correct 14 ms 23876 KB Output is correct
46 Correct 16 ms 23944 KB Output is correct
47 Correct 13 ms 23892 KB Output is correct
48 Correct 13 ms 23952 KB Output is correct
49 Correct 12 ms 23952 KB Output is correct
50 Correct 12 ms 23892 KB Output is correct
51 Correct 12 ms 23880 KB Output is correct
52 Correct 15 ms 23920 KB Output is correct
53 Correct 13 ms 23892 KB Output is correct
54 Correct 12 ms 23892 KB Output is correct
55 Correct 13 ms 23832 KB Output is correct
56 Correct 16 ms 23912 KB Output is correct
57 Correct 15 ms 24068 KB Output is correct
58 Correct 13 ms 23892 KB Output is correct
59 Correct 12 ms 23876 KB Output is correct
60 Correct 15 ms 23884 KB Output is correct
61 Correct 12 ms 23828 KB Output is correct
62 Correct 13 ms 23968 KB Output is correct
63 Correct 12 ms 23928 KB Output is correct
64 Correct 151 ms 34776 KB Output is correct
65 Correct 128 ms 34760 KB Output is correct
66 Correct 138 ms 34692 KB Output is correct
67 Correct 136 ms 34716 KB Output is correct
68 Correct 146 ms 34744 KB Output is correct
69 Correct 146 ms 34804 KB Output is correct
70 Correct 139 ms 34792 KB Output is correct
71 Correct 149 ms 34700 KB Output is correct
72 Correct 154 ms 34804 KB Output is correct
73 Correct 138 ms 49904 KB Output is correct
74 Correct 145 ms 49872 KB Output is correct
75 Correct 129 ms 34580 KB Output is correct
76 Correct 116 ms 34560 KB Output is correct
77 Correct 144 ms 34668 KB Output is correct
78 Correct 136 ms 34628 KB Output is correct
79 Correct 143 ms 34600 KB Output is correct
80 Correct 162 ms 34568 KB Output is correct
81 Correct 106 ms 35188 KB Output is correct
82 Correct 150 ms 34900 KB Output is correct
83 Correct 158 ms 40848 KB Output is correct
84 Correct 162 ms 43492 KB Output is correct
85 Correct 151 ms 43072 KB Output is correct
86 Correct 168 ms 36308 KB Output is correct
87 Correct 147 ms 35720 KB Output is correct
88 Correct 135 ms 36032 KB Output is correct
89 Correct 127 ms 36120 KB Output is correct
90 Correct 121 ms 35916 KB Output is correct
91 Correct 142 ms 36136 KB Output is correct
92 Correct 151 ms 36480 KB Output is correct
93 Correct 124 ms 39452 KB Output is correct
94 Correct 123 ms 41536 KB Output is correct
95 Correct 131 ms 39972 KB Output is correct
96 Correct 140 ms 37768 KB Output is correct
97 Correct 135 ms 35892 KB Output is correct
98 Correct 122 ms 35324 KB Output is correct
99 Correct 121 ms 35148 KB Output is correct
100 Correct 125 ms 38860 KB Output is correct
101 Correct 120 ms 36436 KB Output is correct
102 Correct 122 ms 35636 KB Output is correct
103 Correct 125 ms 35312 KB Output is correct
104 Correct 76 ms 35620 KB Output is correct
105 Correct 153 ms 46124 KB Output is correct
106 Correct 73 ms 35424 KB Output is correct
107 Correct 74 ms 35520 KB Output is correct
108 Correct 147 ms 50760 KB Output is correct
109 Correct 78 ms 35616 KB Output is correct
110 Correct 142 ms 51212 KB Output is correct
111 Correct 113 ms 34624 KB Output is correct