Submission #1095376

# Submission time Handle Problem Language Result Execution time Memory
1095376 2024-10-02T02:45:15 Z ro9669 Power Plant (JOI20_power) C++17
47 / 100
68 ms 10076 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;

typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;

const int maxN = int(2e5)+7;
const int inf = int(1e9)+7;

int n;
vector<int> g[maxN];
string s;
int dp[maxN] , ans = -inf;

void dfs(int u , int par){
    dp[u] = (s[u] - '0');
    int preSum = 0;
    for (int v : g[u]){
        if (v != par){
            dfs(v , u);
            preSum += max(dp[v] , 0);
            ans = max(ans , dp[v] + (s[u] - '0'));
        }
    }
    ans = max(ans , preSum - (s[u] - '0'));
    ans = max(ans , s[u] - '0');
    for (int v : g[u]){
        if (v != par){
            dp[u] = max(dp[u], preSum - max(dp[v] , 0) + dp[v] - (s[u] - '0'));
        }
    }
}

void solve(){
    cin >> n;
    assert(n <= 2000);
    for (int i = 1 ; i < n ; i++){
        int u , v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    cin >> s; s = '#' + s;
    for (int i = 1 ; i <= n ; i++){
        dfs(i , 0);
    }
    cout << ans << "\n";
}

#define name "A"

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(name".INP" , "r")){
        freopen(name".INP" , "r" , stdin);
        freopen(name".OUT" , "w" , stdout);
    }
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen(name".INP" , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
power.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(name".OUT" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 51 ms 5212 KB Output is correct
23 Correct 47 ms 5212 KB Output is correct
24 Correct 49 ms 5212 KB Output is correct
25 Correct 47 ms 5212 KB Output is correct
26 Correct 48 ms 5212 KB Output is correct
27 Correct 47 ms 5236 KB Output is correct
28 Correct 47 ms 5232 KB Output is correct
29 Correct 68 ms 5388 KB Output is correct
30 Correct 66 ms 5208 KB Output is correct
31 Correct 46 ms 5208 KB Output is correct
32 Correct 46 ms 5208 KB Output is correct
33 Correct 52 ms 5212 KB Output is correct
34 Correct 51 ms 5168 KB Output is correct
35 Correct 51 ms 5212 KB Output is correct
36 Correct 51 ms 5212 KB Output is correct
37 Correct 43 ms 5208 KB Output is correct
38 Correct 44 ms 5236 KB Output is correct
39 Correct 53 ms 5208 KB Output is correct
40 Correct 54 ms 5212 KB Output is correct
41 Correct 52 ms 5212 KB Output is correct
42 Correct 49 ms 5208 KB Output is correct
43 Correct 50 ms 5264 KB Output is correct
44 Correct 50 ms 5208 KB Output is correct
45 Correct 50 ms 5208 KB Output is correct
46 Correct 52 ms 5272 KB Output is correct
47 Correct 49 ms 5212 KB Output is correct
48 Correct 48 ms 5208 KB Output is correct
49 Correct 50 ms 5212 KB Output is correct
50 Correct 50 ms 5212 KB Output is correct
51 Correct 50 ms 5268 KB Output is correct
52 Correct 49 ms 5212 KB Output is correct
53 Correct 46 ms 5212 KB Output is correct
54 Correct 50 ms 5208 KB Output is correct
55 Correct 49 ms 5208 KB Output is correct
56 Correct 33 ms 5464 KB Output is correct
57 Correct 66 ms 5212 KB Output is correct
58 Correct 33 ms 5208 KB Output is correct
59 Correct 32 ms 5208 KB Output is correct
60 Correct 68 ms 5212 KB Output is correct
61 Correct 32 ms 5212 KB Output is correct
62 Correct 65 ms 5212 KB Output is correct
63 Correct 43 ms 5236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 51 ms 5212 KB Output is correct
23 Correct 47 ms 5212 KB Output is correct
24 Correct 49 ms 5212 KB Output is correct
25 Correct 47 ms 5212 KB Output is correct
26 Correct 48 ms 5212 KB Output is correct
27 Correct 47 ms 5236 KB Output is correct
28 Correct 47 ms 5232 KB Output is correct
29 Correct 68 ms 5388 KB Output is correct
30 Correct 66 ms 5208 KB Output is correct
31 Correct 46 ms 5208 KB Output is correct
32 Correct 46 ms 5208 KB Output is correct
33 Correct 52 ms 5212 KB Output is correct
34 Correct 51 ms 5168 KB Output is correct
35 Correct 51 ms 5212 KB Output is correct
36 Correct 51 ms 5212 KB Output is correct
37 Correct 43 ms 5208 KB Output is correct
38 Correct 44 ms 5236 KB Output is correct
39 Correct 53 ms 5208 KB Output is correct
40 Correct 54 ms 5212 KB Output is correct
41 Correct 52 ms 5212 KB Output is correct
42 Correct 49 ms 5208 KB Output is correct
43 Correct 50 ms 5264 KB Output is correct
44 Correct 50 ms 5208 KB Output is correct
45 Correct 50 ms 5208 KB Output is correct
46 Correct 52 ms 5272 KB Output is correct
47 Correct 49 ms 5212 KB Output is correct
48 Correct 48 ms 5208 KB Output is correct
49 Correct 50 ms 5212 KB Output is correct
50 Correct 50 ms 5212 KB Output is correct
51 Correct 50 ms 5268 KB Output is correct
52 Correct 49 ms 5212 KB Output is correct
53 Correct 46 ms 5212 KB Output is correct
54 Correct 50 ms 5208 KB Output is correct
55 Correct 49 ms 5208 KB Output is correct
56 Correct 33 ms 5464 KB Output is correct
57 Correct 66 ms 5212 KB Output is correct
58 Correct 33 ms 5208 KB Output is correct
59 Correct 32 ms 5208 KB Output is correct
60 Correct 68 ms 5212 KB Output is correct
61 Correct 32 ms 5212 KB Output is correct
62 Correct 65 ms 5212 KB Output is correct
63 Correct 43 ms 5236 KB Output is correct
64 Runtime error 10 ms 10076 KB Execution killed with signal 6
65 Halted 0 ms 0 KB -