Submission #881068

# Submission time Handle Problem Language Result Execution time Memory
881068 2023-11-30T14:03:46 Z VerdantGMD Power Plant (JOI20_power) C++17
100 / 100
120 ms 27244 KB
#include <iostream>
#include <vector>
using namespace std;

vector<int> tab[200005];
int zp[200005];
int dp[200005];

bool val[200005];
int maxwyn = 0;

void dfs(int p, int parent)
{
    int sum = 0;
    int maxx = 0;
    for(int i = 0; i < tab[p].size(); i++)
    {
        if(tab[p][i] != parent)
        {
            dfs(tab[p][i], p);
        }
    }
    for(int i = 0; i < tab[p].size(); i++)
    {
        if(tab[p][i] != parent)
        {
            sum += zp[tab[p][i]];
            maxx = max(maxx, zp[tab[p][i]]);
        }
    }
    
    if(val[p] == true)
    {
        zp[p] = max(1, sum - 1);
        dp[p] = maxx + 1;
    }
    else
    {
        zp[p] = sum;
        dp[p] = maxx;
    }
    maxwyn = max(zp[p], maxwyn);
    maxwyn = max(dp[p], maxwyn);
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        tab[a].push_back(b);
        tab[b].push_back(a);
    }
    string a;
    cin >> a;
    for(int i = 0; i < a.size(); i++)
    {
        val[i+1] = a[i] - '0';
    }
    
    dfs(1, 0);
    /*for(int i = 1; i <= n; i++)
    {
        cout << i << " " << dp[i] << endl;
    }*/
    cout << maxwyn;
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < tab[p].size(); i++)
      |                    ~~^~~~~~~~~~~~~~~
power.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 0; i < tab[p].size(); i++)
      |                    ~~^~~~~~~~~~~~~~~
power.cpp: In function 'int main()':
power.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < a.size(); i++)
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6700 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 1 ms 7000 KB Output is correct
14 Correct 1 ms 6584 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 1 ms 6744 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6700 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 1 ms 7000 KB Output is correct
14 Correct 1 ms 6584 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 1 ms 6744 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6744 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 7004 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 2 ms 6748 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6832 KB Output is correct
47 Correct 2 ms 6748 KB Output is correct
48 Correct 2 ms 6760 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 2 ms 6748 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 2 ms 6744 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 2 ms 6744 KB Output is correct
58 Correct 2 ms 6744 KB Output is correct
59 Correct 2 ms 6744 KB Output is correct
60 Correct 2 ms 6748 KB Output is correct
61 Correct 2 ms 6752 KB Output is correct
62 Correct 2 ms 7008 KB Output is correct
63 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6700 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 1 ms 7000 KB Output is correct
14 Correct 1 ms 6584 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 1 ms 6744 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6744 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 7004 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 2 ms 6748 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6832 KB Output is correct
47 Correct 2 ms 6748 KB Output is correct
48 Correct 2 ms 6760 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 2 ms 6748 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 2 ms 6744 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 2 ms 6744 KB Output is correct
58 Correct 2 ms 6744 KB Output is correct
59 Correct 2 ms 6744 KB Output is correct
60 Correct 2 ms 6748 KB Output is correct
61 Correct 2 ms 6752 KB Output is correct
62 Correct 2 ms 7008 KB Output is correct
63 Correct 2 ms 6748 KB Output is correct
64 Correct 77 ms 16312 KB Output is correct
65 Correct 67 ms 16272 KB Output is correct
66 Correct 70 ms 16256 KB Output is correct
67 Correct 85 ms 16272 KB Output is correct
68 Correct 94 ms 16252 KB Output is correct
69 Correct 67 ms 16136 KB Output is correct
70 Correct 62 ms 16288 KB Output is correct
71 Correct 63 ms 16236 KB Output is correct
72 Correct 66 ms 16152 KB Output is correct
73 Correct 79 ms 26260 KB Output is correct
74 Correct 90 ms 26212 KB Output is correct
75 Correct 58 ms 16180 KB Output is correct
76 Correct 103 ms 16028 KB Output is correct
77 Correct 63 ms 16024 KB Output is correct
78 Correct 66 ms 16212 KB Output is correct
79 Correct 92 ms 16144 KB Output is correct
80 Correct 65 ms 16180 KB Output is correct
81 Correct 56 ms 16556 KB Output is correct
82 Correct 60 ms 16208 KB Output is correct
83 Correct 118 ms 20340 KB Output is correct
84 Correct 73 ms 21920 KB Output is correct
85 Correct 75 ms 21628 KB Output is correct
86 Correct 83 ms 17300 KB Output is correct
87 Correct 62 ms 16780 KB Output is correct
88 Correct 120 ms 17360 KB Output is correct
89 Correct 66 ms 17416 KB Output is correct
90 Correct 68 ms 17408 KB Output is correct
91 Correct 86 ms 17252 KB Output is correct
92 Correct 70 ms 17636 KB Output is correct
93 Correct 66 ms 19300 KB Output is correct
94 Correct 64 ms 20784 KB Output is correct
95 Correct 104 ms 19764 KB Output is correct
96 Correct 88 ms 18456 KB Output is correct
97 Correct 60 ms 17152 KB Output is correct
98 Correct 71 ms 16796 KB Output is correct
99 Correct 96 ms 16528 KB Output is correct
100 Correct 94 ms 19088 KB Output is correct
101 Correct 60 ms 17492 KB Output is correct
102 Correct 55 ms 16968 KB Output is correct
103 Correct 61 ms 16816 KB Output is correct
104 Correct 42 ms 17092 KB Output is correct
105 Correct 110 ms 23624 KB Output is correct
106 Correct 80 ms 16832 KB Output is correct
107 Correct 46 ms 16836 KB Output is correct
108 Correct 84 ms 26960 KB Output is correct
109 Correct 41 ms 17092 KB Output is correct
110 Correct 102 ms 27244 KB Output is correct
111 Correct 62 ms 16156 KB Output is correct