Submission #936343

# Submission time Handle Problem Language Result Execution time Memory
936343 2024-03-01T16:27:32 Z ace5 Power Plant (JOI20_power) C++17
100 / 100
168 ms 42420 KB
#include <bits/stdc++.h>

using namespace std;

#define int int64_t

vector<vector<int>> g;
vector<int> dpn;
vector<int> dpy;
vector<bool> gen;

void dfs(int v,int p)
{
    vector<int> sdpy,sdpn;
    for(auto u:g[v])
    {
        if(u != p)
        {
            dfs(u,v);
            sdpy.push_back(dpy[u]);
            sdpn.push_back(dpn[u]);
        }
    }
    if(gen[v] == 0)
    {
        for(int i = 0;i < sdpy.size();++i)
        {
            dpy[v] += sdpy[i];
        }
        dpn[v] = dpy[v];
        int v2 = 0;
        for(int i = 0;i < sdpn.size();++i)
        {
            v2 = max(v2,sdpn[i]);
        }
        dpn[v] = max(dpn[v],v2);
    }
    else
    {
        for(int i = 0;i < sdpy.size();++i)
        {
            dpy[v] += sdpy[i];
        }
        dpy[v] --;
        dpy[v] = max(dpy[v],int64_t(1));
        for(int i = 0;i < sdpy.size();++i)
        {
            dpn[v] += sdpy[i];
        }
        dpn[v]--;
        int v2 = 0;
        for(int i =0;i < sdpy.size();++i)
        {
            v2 = max(v2,sdpy[i]);
        }
        v2++;
        dpn[v] = max(dpn[v],v2);
        int v3 = 0;
        for(int i = 0;i < sdpn.size();++i)
        {
            v3 = max(v3,sdpn[i]);
        }
        dpn[v] = max(dpn[v],v3);
    }
    //cout << v << ' ' << dpy[v] << ' ' << dpn[v] << "\n";
    return ;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    g.resize(n);
    dpn.resize(n);
    dpy.resize(n);
    gen.resize(n);
    for(int i = 0;i < n-1;++i)
    {
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    string s;
    cin >> s;
    for(int i =0 ;i < n;++i)
    {
        gen[i] = (s[i] == '1');
    }
    dfs(0,-1);
    cout << dpn[0] << "\n";
}

Compilation message

power.cpp: In function 'void dfs(int64_t, int64_t)':
power.cpp:26:25: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for(int i = 0;i < sdpy.size();++i)
      |                       ~~^~~~~~~~~~~~~
power.cpp:32:25: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int i = 0;i < sdpn.size();++i)
      |                       ~~^~~~~~~~~~~~~
power.cpp:40:25: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i = 0;i < sdpy.size();++i)
      |                       ~~^~~~~~~~~~~~~
power.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int i = 0;i < sdpy.size();++i)
      |                       ~~^~~~~~~~~~~~~
power.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int i =0;i < sdpy.size();++i)
      |                      ~~^~~~~~~~~~~~~
power.cpp:59:25: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int i = 0;i < sdpn.size();++i)
      |                       ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 464 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 860 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 868 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 464 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 860 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 868 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 126 ms 18712 KB Output is correct
65 Correct 114 ms 18632 KB Output is correct
66 Correct 160 ms 18884 KB Output is correct
67 Correct 111 ms 18756 KB Output is correct
68 Correct 152 ms 18800 KB Output is correct
69 Correct 146 ms 18716 KB Output is correct
70 Correct 147 ms 18752 KB Output is correct
71 Correct 118 ms 18684 KB Output is correct
72 Correct 168 ms 18732 KB Output is correct
73 Correct 165 ms 40468 KB Output is correct
74 Correct 142 ms 40344 KB Output is correct
75 Correct 131 ms 19848 KB Output is correct
76 Correct 110 ms 19840 KB Output is correct
77 Correct 120 ms 18668 KB Output is correct
78 Correct 122 ms 18768 KB Output is correct
79 Correct 109 ms 18656 KB Output is correct
80 Correct 149 ms 18604 KB Output is correct
81 Correct 116 ms 21156 KB Output is correct
82 Correct 94 ms 19604 KB Output is correct
83 Correct 160 ms 28460 KB Output is correct
84 Correct 159 ms 32768 KB Output is correct
85 Correct 165 ms 32160 KB Output is correct
86 Correct 117 ms 21428 KB Output is correct
87 Correct 120 ms 19988 KB Output is correct
88 Correct 124 ms 20096 KB Output is correct
89 Correct 109 ms 19976 KB Output is correct
90 Correct 134 ms 19512 KB Output is correct
91 Correct 115 ms 20060 KB Output is correct
92 Correct 81 ms 20672 KB Output is correct
93 Correct 84 ms 26236 KB Output is correct
94 Correct 89 ms 28216 KB Output is correct
95 Correct 85 ms 26540 KB Output is correct
96 Correct 86 ms 22720 KB Output is correct
97 Correct 118 ms 19692 KB Output is correct
98 Correct 104 ms 18796 KB Output is correct
99 Correct 83 ms 18744 KB Output is correct
100 Correct 88 ms 24884 KB Output is correct
101 Correct 84 ms 20488 KB Output is correct
102 Correct 79 ms 19032 KB Output is correct
103 Correct 79 ms 19016 KB Output is correct
104 Correct 54 ms 24088 KB Output is correct
105 Correct 100 ms 34604 KB Output is correct
106 Correct 57 ms 23748 KB Output is correct
107 Correct 60 ms 24220 KB Output is correct
108 Correct 110 ms 41832 KB Output is correct
109 Correct 61 ms 24004 KB Output is correct
110 Correct 112 ms 42420 KB Output is correct
111 Correct 80 ms 18748 KB Output is correct