Submission #763250

# Submission time Handle Problem Language Result Execution time Memory
763250 2023-06-22T07:13:05 Z vjudge1 Power Plant (JOI20_power) C++17
100 / 100
185 ms 28424 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 2e5 + 5;

vector<ll> adj[maxn];
string s;
ll ans = 1;
ll dp[maxn];
void dfs(ll src, ll parent)
{
    ll maxt = -1;
    for (auto sex: adj[src])
    {
        if (sex != parent)
        {
            dfs(sex, src);
            dp[src] += dp[sex];
            maxt = max(maxt, dp[sex]);
        }
    }
    ll gay = s[src - 1] - '0';
    dp[src] = max(gay,  dp[src] - gay);
    ans = max({ans, maxt + gay, dp[src]});
}

int main()
{
    ll n;
    cin >> n;
    ll u, v;
    for (ll i = 1; i <= n - 1; ++i)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cin >> s;
    dfs(1, 0);
    cout << ans;
    
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 5000 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 5000 KB Output is correct
20 Correct 3 ms 4928 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 5000 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 5000 KB Output is correct
20 Correct 3 ms 4928 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5016 KB Output is correct
26 Correct 3 ms 5016 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 5 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5116 KB Output is correct
33 Correct 4 ms 5012 KB Output is correct
34 Correct 5 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 4 ms 5012 KB Output is correct
37 Correct 3 ms 5012 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 4 ms 5112 KB Output is correct
45 Correct 4 ms 5108 KB Output is correct
46 Correct 3 ms 5084 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 4 ms 5148 KB Output is correct
51 Correct 4 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 4 ms 5036 KB Output is correct
54 Correct 4 ms 5140 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5016 KB Output is correct
59 Correct 3 ms 5016 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5200 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 5000 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 5000 KB Output is correct
20 Correct 3 ms 4928 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5016 KB Output is correct
26 Correct 3 ms 5016 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 5 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5116 KB Output is correct
33 Correct 4 ms 5012 KB Output is correct
34 Correct 5 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 4 ms 5012 KB Output is correct
37 Correct 3 ms 5012 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 4 ms 5112 KB Output is correct
45 Correct 4 ms 5108 KB Output is correct
46 Correct 3 ms 5084 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 4 ms 5148 KB Output is correct
51 Correct 4 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 4 ms 5036 KB Output is correct
54 Correct 4 ms 5140 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5016 KB Output is correct
59 Correct 3 ms 5016 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5200 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 123 ms 15740 KB Output is correct
65 Correct 132 ms 15712 KB Output is correct
66 Correct 126 ms 15768 KB Output is correct
67 Correct 132 ms 15744 KB Output is correct
68 Correct 178 ms 15844 KB Output is correct
69 Correct 127 ms 15700 KB Output is correct
70 Correct 145 ms 15724 KB Output is correct
71 Correct 130 ms 15732 KB Output is correct
72 Correct 163 ms 15780 KB Output is correct
73 Correct 141 ms 27284 KB Output is correct
74 Correct 151 ms 27312 KB Output is correct
75 Correct 161 ms 16984 KB Output is correct
76 Correct 161 ms 16944 KB Output is correct
77 Correct 129 ms 15620 KB Output is correct
78 Correct 128 ms 15648 KB Output is correct
79 Correct 159 ms 15744 KB Output is correct
80 Correct 146 ms 15708 KB Output is correct
81 Correct 115 ms 15856 KB Output is correct
82 Correct 118 ms 15784 KB Output is correct
83 Correct 168 ms 20928 KB Output is correct
84 Correct 184 ms 22920 KB Output is correct
85 Correct 135 ms 22624 KB Output is correct
86 Correct 185 ms 17004 KB Output is correct
87 Correct 126 ms 16416 KB Output is correct
88 Correct 123 ms 16604 KB Output is correct
89 Correct 151 ms 16612 KB Output is correct
90 Correct 134 ms 16408 KB Output is correct
91 Correct 144 ms 16604 KB Output is correct
92 Correct 154 ms 16932 KB Output is correct
93 Correct 126 ms 19268 KB Output is correct
94 Correct 143 ms 21008 KB Output is correct
95 Correct 130 ms 19580 KB Output is correct
96 Correct 120 ms 17656 KB Output is correct
97 Correct 125 ms 16292 KB Output is correct
98 Correct 127 ms 15908 KB Output is correct
99 Correct 131 ms 15848 KB Output is correct
100 Correct 177 ms 18732 KB Output is correct
101 Correct 123 ms 16580 KB Output is correct
102 Correct 150 ms 15968 KB Output is correct
103 Correct 129 ms 16048 KB Output is correct
104 Correct 105 ms 16312 KB Output is correct
105 Correct 160 ms 24160 KB Output is correct
106 Correct 116 ms 16296 KB Output is correct
107 Correct 109 ms 16352 KB Output is correct
108 Correct 175 ms 28028 KB Output is correct
109 Correct 121 ms 16280 KB Output is correct
110 Correct 140 ms 28424 KB Output is correct
111 Correct 140 ms 15656 KB Output is correct