Submission #1049040

# Submission time Handle Problem Language Result Execution time Memory
1049040 2024-08-08T12:24:44 Z crafticat Power Plant (JOI20_power) C++17
100 / 100
72 ms 26960 KB
#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

#include <utility>

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;

#define temp(T) template<class T>
temp(T) using V = vector<T>;
using vi = V<int>;
using vl = V<ll>;
using vvi = V<vi>;
using vpi = V<pi>;
using vb = V<bool>;
using vvb = V<vb>;
vi dx = {0,1,-1,0};
vi dy = {1,0,0,-1};

#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define f first
#define s second

#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)

using str = string;

const int MOD = 1e9 + 7;
const ll BIG = 1e18;
const int INF = 1e9 + 2;

temp(T) bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0; } // set a = min(a,b)
temp(T) bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; } // set a = max(a,b)

void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void setIO(str s = "") {
    unsyncIO();
    if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO
}

#define read(x) int x; cin >> x

temp(T) void pr(T x) {
    cout << to_string(x);
}
temp(T) void prln(T x) {
    cout << to_string(x) << "\n";
}


vi readV(int n) {
    vi input(n);
    F0R(i,n)
        cin >> input[i];
    return input;
}

vi dp2;
vi up;
vvi g;
string active;

int get(int k, int y) {
    if (y != - 1 && active[y] == '1') { k--; if (k < 1) k = 1;}
    return k;
}

void dfs(int x, int p) {
    each(y, g[x]) {
        if (y == p) continue;
        dfs(y, x);
        int cs = dp2[y];
        dp2[x] += get(cs, y);
    }
}

void dfs2(int x, int p, int pp) {
    if (p != -1) {
        up[x] = get(dp2[p] - get(dp2[x], x) + get(up[p], pp), p);
    }

    each(y, g[x]) {
        if (y == p) continue;
        dfs2(y, x, p);
    }
}
int test(int x, int p) {
    int ans = 0;
    each(y, g[x]) {
        if (y == p) continue;
        int cs = test(y, x);
    }
    return ans;
}

int main() {
    setIO();

    read(n);

    g.rsz(n + 1);
    F0R(i, n -1) {
        int a, b; cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }

    cin >> active;
    active = " " + active;
    dp2.rsz(n + 1);
    up.rsz(n + 1);

    dfs(1, -1);
    dfs2(1, -1, -1);

    int ans =0;
    FOR(i, 1, n + 1) {
        int sum = dp2[i] + up[i];
        if (active[i] == '1' and sum > 2) sum--;
        if (active[i] == '1' and sum == 0) sum = 1;
        ckmax(ans, sum);
    }

    cout << ans;

    return 0;
}

Compilation message

power.cpp: In function 'int test(int, int)':
power.cpp:117:13: warning: unused variable 'cs' [-Wunused-variable]
  117 |         int cs = test(y, x);
      |             ^~
power.cpp: In function 'void setIn(str)':
power.cpp:60:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
power.cpp: In function 'void setOut(str)':
power.cpp:61:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 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 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 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 376 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 1 ms 604 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 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 604 KB Output is correct
49 Correct 0 ms 604 KB Output is correct
50 Correct 0 ms 604 KB Output is correct
51 Correct 0 ms 604 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 612 KB Output is correct
54 Correct 0 ms 604 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 604 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 600 KB Output is correct
63 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 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 376 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 1 ms 604 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 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 604 KB Output is correct
49 Correct 0 ms 604 KB Output is correct
50 Correct 0 ms 604 KB Output is correct
51 Correct 0 ms 604 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 612 KB Output is correct
54 Correct 0 ms 604 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 604 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 600 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 52 ms 13268 KB Output is correct
65 Correct 52 ms 16056 KB Output is correct
66 Correct 49 ms 16060 KB Output is correct
67 Correct 52 ms 15996 KB Output is correct
68 Correct 61 ms 16056 KB Output is correct
69 Correct 61 ms 16072 KB Output is correct
70 Correct 50 ms 16088 KB Output is correct
71 Correct 46 ms 16116 KB Output is correct
72 Correct 51 ms 16076 KB Output is correct
73 Correct 60 ms 26200 KB Output is correct
74 Correct 61 ms 26104 KB Output is correct
75 Correct 45 ms 15824 KB Output is correct
76 Correct 48 ms 15980 KB Output is correct
77 Correct 49 ms 15820 KB Output is correct
78 Correct 53 ms 15820 KB Output is correct
79 Correct 49 ms 15828 KB Output is correct
80 Correct 52 ms 15832 KB Output is correct
81 Correct 50 ms 16252 KB Output is correct
82 Correct 53 ms 16016 KB Output is correct
83 Correct 56 ms 20092 KB Output is correct
84 Correct 66 ms 21848 KB Output is correct
85 Correct 53 ms 21652 KB Output is correct
86 Correct 57 ms 17104 KB Output is correct
87 Correct 55 ms 16588 KB Output is correct
88 Correct 53 ms 17160 KB Output is correct
89 Correct 51 ms 17116 KB Output is correct
90 Correct 48 ms 16944 KB Output is correct
91 Correct 52 ms 17084 KB Output is correct
92 Correct 51 ms 17340 KB Output is correct
93 Correct 47 ms 19104 KB Output is correct
94 Correct 58 ms 20756 KB Output is correct
95 Correct 47 ms 19592 KB Output is correct
96 Correct 48 ms 18196 KB Output is correct
97 Correct 56 ms 16936 KB Output is correct
98 Correct 49 ms 16680 KB Output is correct
99 Correct 48 ms 16328 KB Output is correct
100 Correct 48 ms 18872 KB Output is correct
101 Correct 72 ms 17228 KB Output is correct
102 Correct 63 ms 16724 KB Output is correct
103 Correct 54 ms 16620 KB Output is correct
104 Correct 34 ms 16848 KB Output is correct
105 Correct 65 ms 23756 KB Output is correct
106 Correct 36 ms 16836 KB Output is correct
107 Correct 32 ms 16844 KB Output is correct
108 Correct 61 ms 26572 KB Output is correct
109 Correct 36 ms 16840 KB Output is correct
110 Correct 70 ms 26960 KB Output is correct
111 Correct 45 ms 15848 KB Output is correct