Submission #588761

# Submission time Handle Problem Language Result Execution time Memory
588761 2022-07-04T03:30:01 Z Loki_Nguyen Power Plant (JOI20_power) C++14
100 / 100
161 ms 31668 KB
#include <bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "test"
#define pii pair<pll, pll>
using namespace std;
using ll = int;
const int N = 2e5+5;
const ll mod = 1e8 + 7;
const ll base = 113;
const ll inf = 1e9;
int m, n, t, k, a[N], tong, d[N], dp[N], h[N], ans;
vector<int> adj[N];
string s;
int dfs(int u, int p = 0)
{
    if(dp[u] != -1)return dp[u];
    int sum = 0, cnt = 0, mx = 0;
    for(int v: adj[u])
    {
        if(v == p)continue;
        sum += dfs(v, u);
        mx = max(mx, dfs(v, u));
        ++cnt;
    }
    if(s[u] == '1')
    {
        ans = max(ans, mx+1);
        sum = max(sum-1, 1);
    }
    ans = max(ans, sum);
    return dp[u] = sum;
}
void sol()
{
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    cin >> s;
    s = " " + s; 
    fill_n(dp, n+1, -1);
    dfs(1);
    cout << ans;
}
int main()   
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    cout.tie(0);
    if (fopen(task ".inp", "r"))
    {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int ntest = 1;
    // cin >> ntest;   
    while (ntest-- > 0)
        sol();
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
power.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 5024 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 5028 KB Output is correct
10 Correct 2 ms 5036 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 5024 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 5028 KB Output is correct
10 Correct 2 ms 5036 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 5028 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5040 KB Output is correct
25 Correct 4 ms 5044 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5036 KB Output is correct
29 Correct 3 ms 5224 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 5 ms 5044 KB Output is correct
33 Correct 3 ms 5044 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5032 KB Output is correct
37 Correct 5 ms 5040 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5132 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5172 KB Output is correct
45 Correct 3 ms 5092 KB Output is correct
46 Correct 3 ms 5040 KB Output is correct
47 Correct 4 ms 5116 KB Output is correct
48 Correct 4 ms 5204 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 3 ms 5168 KB Output is correct
51 Correct 4 ms 5044 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 4 ms 5168 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 4 ms 5028 KB Output is correct
57 Correct 3 ms 5172 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 3 ms 5040 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 5024 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 5028 KB Output is correct
10 Correct 2 ms 5036 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 5028 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5040 KB Output is correct
25 Correct 4 ms 5044 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5036 KB Output is correct
29 Correct 3 ms 5224 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 5 ms 5044 KB Output is correct
33 Correct 3 ms 5044 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5032 KB Output is correct
37 Correct 5 ms 5040 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5132 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5172 KB Output is correct
45 Correct 3 ms 5092 KB Output is correct
46 Correct 3 ms 5040 KB Output is correct
47 Correct 4 ms 5116 KB Output is correct
48 Correct 4 ms 5204 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 3 ms 5168 KB Output is correct
51 Correct 4 ms 5044 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 4 ms 5168 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 4 ms 5028 KB Output is correct
57 Correct 3 ms 5172 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 3 ms 5040 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 113 ms 15180 KB Output is correct
65 Correct 144 ms 15216 KB Output is correct
66 Correct 126 ms 15228 KB Output is correct
67 Correct 124 ms 15192 KB Output is correct
68 Correct 108 ms 15132 KB Output is correct
69 Correct 131 ms 15224 KB Output is correct
70 Correct 135 ms 15188 KB Output is correct
71 Correct 120 ms 15208 KB Output is correct
72 Correct 132 ms 15108 KB Output is correct
73 Correct 142 ms 30312 KB Output is correct
74 Correct 153 ms 30428 KB Output is correct
75 Correct 115 ms 15012 KB Output is correct
76 Correct 105 ms 15060 KB Output is correct
77 Correct 120 ms 15012 KB Output is correct
78 Correct 111 ms 15016 KB Output is correct
79 Correct 113 ms 15004 KB Output is correct
80 Correct 150 ms 15020 KB Output is correct
81 Correct 94 ms 15440 KB Output is correct
82 Correct 100 ms 15288 KB Output is correct
83 Correct 121 ms 21348 KB Output is correct
84 Correct 136 ms 23896 KB Output is correct
85 Correct 161 ms 23460 KB Output is correct
86 Correct 147 ms 16836 KB Output is correct
87 Correct 113 ms 16100 KB Output is correct
88 Correct 139 ms 16536 KB Output is correct
89 Correct 119 ms 16592 KB Output is correct
90 Correct 156 ms 16232 KB Output is correct
91 Correct 125 ms 16640 KB Output is correct
92 Correct 119 ms 16928 KB Output is correct
93 Correct 107 ms 19920 KB Output is correct
94 Correct 102 ms 22028 KB Output is correct
95 Correct 99 ms 20408 KB Output is correct
96 Correct 124 ms 18212 KB Output is correct
97 Correct 113 ms 16336 KB Output is correct
98 Correct 102 ms 15740 KB Output is correct
99 Correct 107 ms 15568 KB Output is correct
100 Correct 139 ms 19380 KB Output is correct
101 Correct 138 ms 16908 KB Output is correct
102 Correct 120 ms 16024 KB Output is correct
103 Correct 99 ms 15716 KB Output is correct
104 Correct 74 ms 16056 KB Output is correct
105 Correct 134 ms 26536 KB Output is correct
106 Correct 66 ms 15932 KB Output is correct
107 Correct 67 ms 15848 KB Output is correct
108 Correct 155 ms 31168 KB Output is correct
109 Correct 67 ms 16064 KB Output is correct
110 Correct 132 ms 31668 KB Output is correct
111 Correct 120 ms 15048 KB Output is correct