Submission #773247

# Submission time Handle Problem Language Result Execution time Memory
773247 2023-07-04T17:36:04 Z CyberCow Power Plant (JOI20_power) C++17
47 / 100
56 ms 596 KB
//#include <bits/stdc++.h>
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const int N = 2005;
int n;
vector<int> v[N];
int dp[N], a[N];

void Dfs(int g, int p)
{
    for (auto to : v[g])
    {
        if (to != p)
        {
            Dfs(to, g);
        }
    }
    if (p == -1)
    {
        int ma = 0, gum = 0;
        for(auto to: v[g])
        {
            ma = max(ma, dp[to]);
            gum += dp[to];
        }
        dp[g] = max(ma + 1, gum - 1);
        return;
    }
    int gum = 0;
    for (auto to : v[g])
    {
        if (to != p)
            gum += dp[to];
    }
    if (a[g] == 1)
        dp[g] = max(gum - 1, 1);
    else
        dp[g] = gum;
}

void solve()
{
    int i, j, x, y;
    cin >> n;
    for (i = 0; i < n - 1; i++)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    char c;
    for (i = 1; i <= n; i++)
    {
        cin >> c;
        a[i] = c - '0';
    }
    int ans = 0;
    for ( i = 1; i <= n; i++)   
    {
        if (a[i] == 1)
        {
            for ( j = 1; j <= n; j++)
            {
                dp[j] = 0;
            }
            Dfs(i, -1);
            ans = max(ans, dp[i]);
        }
    }
    cout << ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 376 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 376 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 39 ms 468 KB Output is correct
23 Correct 36 ms 460 KB Output is correct
24 Correct 32 ms 468 KB Output is correct
25 Correct 26 ms 468 KB Output is correct
26 Correct 14 ms 492 KB Output is correct
27 Correct 5 ms 472 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 56 ms 580 KB Output is correct
30 Correct 30 ms 468 KB Output is correct
31 Correct 36 ms 364 KB Output is correct
32 Correct 19 ms 468 KB Output is correct
33 Correct 38 ms 384 KB Output is correct
34 Correct 21 ms 468 KB Output is correct
35 Correct 11 ms 468 KB Output is correct
36 Correct 5 ms 468 KB Output is correct
37 Correct 24 ms 452 KB Output is correct
38 Correct 18 ms 468 KB Output is correct
39 Correct 53 ms 512 KB Output is correct
40 Correct 28 ms 468 KB Output is correct
41 Correct 17 ms 528 KB Output is correct
42 Correct 33 ms 484 KB Output is correct
43 Correct 6 ms 468 KB Output is correct
44 Correct 40 ms 500 KB Output is correct
45 Correct 31 ms 496 KB Output is correct
46 Correct 25 ms 492 KB Output is correct
47 Correct 11 ms 468 KB Output is correct
48 Correct 39 ms 520 KB Output is correct
49 Correct 40 ms 520 KB Output is correct
50 Correct 40 ms 388 KB Output is correct
51 Correct 40 ms 484 KB Output is correct
52 Correct 37 ms 468 KB Output is correct
53 Correct 28 ms 468 KB Output is correct
54 Correct 39 ms 480 KB Output is correct
55 Correct 39 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 22 ms 480 KB Output is correct
59 Correct 22 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 33 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 376 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 39 ms 468 KB Output is correct
23 Correct 36 ms 460 KB Output is correct
24 Correct 32 ms 468 KB Output is correct
25 Correct 26 ms 468 KB Output is correct
26 Correct 14 ms 492 KB Output is correct
27 Correct 5 ms 472 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 56 ms 580 KB Output is correct
30 Correct 30 ms 468 KB Output is correct
31 Correct 36 ms 364 KB Output is correct
32 Correct 19 ms 468 KB Output is correct
33 Correct 38 ms 384 KB Output is correct
34 Correct 21 ms 468 KB Output is correct
35 Correct 11 ms 468 KB Output is correct
36 Correct 5 ms 468 KB Output is correct
37 Correct 24 ms 452 KB Output is correct
38 Correct 18 ms 468 KB Output is correct
39 Correct 53 ms 512 KB Output is correct
40 Correct 28 ms 468 KB Output is correct
41 Correct 17 ms 528 KB Output is correct
42 Correct 33 ms 484 KB Output is correct
43 Correct 6 ms 468 KB Output is correct
44 Correct 40 ms 500 KB Output is correct
45 Correct 31 ms 496 KB Output is correct
46 Correct 25 ms 492 KB Output is correct
47 Correct 11 ms 468 KB Output is correct
48 Correct 39 ms 520 KB Output is correct
49 Correct 40 ms 520 KB Output is correct
50 Correct 40 ms 388 KB Output is correct
51 Correct 40 ms 484 KB Output is correct
52 Correct 37 ms 468 KB Output is correct
53 Correct 28 ms 468 KB Output is correct
54 Correct 39 ms 480 KB Output is correct
55 Correct 39 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 22 ms 480 KB Output is correct
59 Correct 22 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 33 ms 468 KB Output is correct
64 Runtime error 1 ms 596 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -