Submission #924791

# Submission time Handle Problem Language Result Execution time Memory
924791 2024-02-09T16:50:34 Z BBart888 Power Plant (JOI20_power) C++14
100 / 100
98 ms 31572 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <stack>
#include <stdio.h>     
#include <stdlib.h>     


using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Mat = vector<vector<ll>>;

const ll MOD = 1e9 + 7;
const int MAXN = 2e5 + 111;
const int K = 500;


int n;
vector<int> adj[MAXN];
bool czy_ma[MAXN];
int dp[MAXN];
int ans;



void dfs(int v, int p)
{
    int s = 0;
    for (auto u : adj[v])
    {
        if (u == p)
            continue;
        dfs(u, v);
        s += dp[u];
    }
    if (czy_ma[v])
    {
        for (auto u : adj[v])
        {
            if (u == p)
                continue;
            ans = max(ans, dp[u] + 1);
        }
        dp[v] += s;
        dp[v]--;
        dp[v] = max(dp[v], 1);
    }
    else
    {
        dp[v] += s;
    }
    ans = max(ans, dp[v]);
    
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);


    //freopen("art2.in", "r", stdin);
    //freopen("art2.out", "w", stdout);

    cin >> n;

    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i = 1; i <= n; i++)
    {
        char c;
        cin >> c;
        czy_ma[i] = (c - '0');
    }

    dfs(1, 1);

    cout << ans << '\n';







    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5720 KB Output is correct
2 Correct 2 ms 5720 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5812 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5816 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 1 ms 5724 KB Output is correct
19 Correct 2 ms 5720 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5720 KB Output is correct
2 Correct 2 ms 5720 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5812 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5816 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 1 ms 5724 KB Output is correct
19 Correct 2 ms 5720 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 2 ms 5980 KB Output is correct
24 Correct 2 ms 5976 KB Output is correct
25 Correct 2 ms 5980 KB Output is correct
26 Correct 2 ms 5980 KB Output is correct
27 Correct 2 ms 5980 KB Output is correct
28 Correct 2 ms 6032 KB Output is correct
29 Correct 3 ms 6120 KB Output is correct
30 Correct 2 ms 5980 KB Output is correct
31 Correct 2 ms 5980 KB Output is correct
32 Correct 2 ms 5816 KB Output is correct
33 Correct 2 ms 5980 KB Output is correct
34 Correct 2 ms 5980 KB Output is correct
35 Correct 2 ms 5980 KB Output is correct
36 Correct 2 ms 5980 KB Output is correct
37 Correct 2 ms 5980 KB Output is correct
38 Correct 2 ms 5980 KB Output is correct
39 Correct 2 ms 5980 KB Output is correct
40 Correct 2 ms 5980 KB Output is correct
41 Correct 2 ms 5976 KB Output is correct
42 Correct 2 ms 5980 KB Output is correct
43 Correct 2 ms 6064 KB Output is correct
44 Correct 2 ms 5980 KB Output is correct
45 Correct 2 ms 5980 KB Output is correct
46 Correct 3 ms 5976 KB Output is correct
47 Correct 2 ms 5980 KB Output is correct
48 Correct 2 ms 5980 KB Output is correct
49 Correct 3 ms 5976 KB Output is correct
50 Correct 2 ms 5980 KB Output is correct
51 Correct 2 ms 5980 KB Output is correct
52 Correct 2 ms 5980 KB Output is correct
53 Correct 2 ms 5980 KB Output is correct
54 Correct 2 ms 5980 KB Output is correct
55 Correct 2 ms 5980 KB Output is correct
56 Correct 2 ms 5980 KB Output is correct
57 Correct 2 ms 5980 KB Output is correct
58 Correct 2 ms 6048 KB Output is correct
59 Correct 2 ms 6232 KB Output is correct
60 Correct 2 ms 5968 KB Output is correct
61 Correct 2 ms 5980 KB Output is correct
62 Correct 2 ms 5980 KB Output is correct
63 Correct 2 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5720 KB Output is correct
2 Correct 2 ms 5720 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5812 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5816 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 1 ms 5724 KB Output is correct
19 Correct 2 ms 5720 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 2 ms 5980 KB Output is correct
24 Correct 2 ms 5976 KB Output is correct
25 Correct 2 ms 5980 KB Output is correct
26 Correct 2 ms 5980 KB Output is correct
27 Correct 2 ms 5980 KB Output is correct
28 Correct 2 ms 6032 KB Output is correct
29 Correct 3 ms 6120 KB Output is correct
30 Correct 2 ms 5980 KB Output is correct
31 Correct 2 ms 5980 KB Output is correct
32 Correct 2 ms 5816 KB Output is correct
33 Correct 2 ms 5980 KB Output is correct
34 Correct 2 ms 5980 KB Output is correct
35 Correct 2 ms 5980 KB Output is correct
36 Correct 2 ms 5980 KB Output is correct
37 Correct 2 ms 5980 KB Output is correct
38 Correct 2 ms 5980 KB Output is correct
39 Correct 2 ms 5980 KB Output is correct
40 Correct 2 ms 5980 KB Output is correct
41 Correct 2 ms 5976 KB Output is correct
42 Correct 2 ms 5980 KB Output is correct
43 Correct 2 ms 6064 KB Output is correct
44 Correct 2 ms 5980 KB Output is correct
45 Correct 2 ms 5980 KB Output is correct
46 Correct 3 ms 5976 KB Output is correct
47 Correct 2 ms 5980 KB Output is correct
48 Correct 2 ms 5980 KB Output is correct
49 Correct 3 ms 5976 KB Output is correct
50 Correct 2 ms 5980 KB Output is correct
51 Correct 2 ms 5980 KB Output is correct
52 Correct 2 ms 5980 KB Output is correct
53 Correct 2 ms 5980 KB Output is correct
54 Correct 2 ms 5980 KB Output is correct
55 Correct 2 ms 5980 KB Output is correct
56 Correct 2 ms 5980 KB Output is correct
57 Correct 2 ms 5980 KB Output is correct
58 Correct 2 ms 6048 KB Output is correct
59 Correct 2 ms 6232 KB Output is correct
60 Correct 2 ms 5968 KB Output is correct
61 Correct 2 ms 5980 KB Output is correct
62 Correct 2 ms 5980 KB Output is correct
63 Correct 2 ms 5976 KB Output is correct
64 Correct 91 ms 15468 KB Output is correct
65 Correct 58 ms 15192 KB Output is correct
66 Correct 66 ms 15188 KB Output is correct
67 Correct 63 ms 15184 KB Output is correct
68 Correct 60 ms 15016 KB Output is correct
69 Correct 58 ms 15204 KB Output is correct
70 Correct 69 ms 15140 KB Output is correct
71 Correct 62 ms 15256 KB Output is correct
72 Correct 59 ms 15188 KB Output is correct
73 Correct 98 ms 30288 KB Output is correct
74 Correct 96 ms 30300 KB Output is correct
75 Correct 64 ms 14928 KB Output is correct
76 Correct 62 ms 14968 KB Output is correct
77 Correct 95 ms 15100 KB Output is correct
78 Correct 59 ms 14928 KB Output is correct
79 Correct 83 ms 14928 KB Output is correct
80 Correct 60 ms 14928 KB Output is correct
81 Correct 53 ms 15240 KB Output is correct
82 Correct 58 ms 15308 KB Output is correct
83 Correct 75 ms 21328 KB Output is correct
84 Correct 74 ms 23896 KB Output is correct
85 Correct 79 ms 23512 KB Output is correct
86 Correct 64 ms 16724 KB Output is correct
87 Correct 61 ms 15900 KB Output is correct
88 Correct 83 ms 16468 KB Output is correct
89 Correct 64 ms 16464 KB Output is correct
90 Correct 61 ms 16208 KB Output is correct
91 Correct 64 ms 16464 KB Output is correct
92 Correct 62 ms 16820 KB Output is correct
93 Correct 67 ms 19856 KB Output is correct
94 Correct 75 ms 21844 KB Output is correct
95 Correct 63 ms 20400 KB Output is correct
96 Correct 68 ms 18252 KB Output is correct
97 Correct 62 ms 16212 KB Output is correct
98 Correct 61 ms 15792 KB Output is correct
99 Correct 60 ms 15440 KB Output is correct
100 Correct 68 ms 19128 KB Output is correct
101 Correct 62 ms 16720 KB Output is correct
102 Correct 74 ms 16008 KB Output is correct
103 Correct 62 ms 15696 KB Output is correct
104 Correct 48 ms 15980 KB Output is correct
105 Correct 79 ms 26452 KB Output is correct
106 Correct 41 ms 15560 KB Output is correct
107 Correct 41 ms 15560 KB Output is correct
108 Correct 98 ms 31060 KB Output is correct
109 Correct 44 ms 15860 KB Output is correct
110 Correct 82 ms 31572 KB Output is correct
111 Correct 55 ms 15020 KB Output is correct