Submission #766754

# Submission time Handle Problem Language Result Execution time Memory
766754 2023-06-26T06:36:56 Z Dorost Power Plant (JOI20_power) C++17
0 / 100
4 ms 4948 KB
/*  * In the name of GOD  */

#include "bits/stdc++.h"

using namespace std;

typedef long long ll; 
typedef pair <int, int> pii;
#define F first
#define S second
#define mk make_pair
const int N = 201234;
vector <int> g[N];
int dp[N];
bool f[N];

void dfs (int v, int p = -1) {
    dp[v] = f[v];
    int sum1 = 0;
    for (int u : g[v]) {
        if (u != p) {
            dfs (u, v); 
            sum1 += dp[u];
        }
    }   
    if (f[v]) {
        dp[v] = max(dp[v], sum1 - 1); 
    } else {
        dp[v] = max(dp[v], sum1);
    }   
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int n;
    cin >> n;
    if (n > 2000)
        return 0;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }   
    for (int i = 1; i <= n; i++) {
        char c;
        cin >> c;
        f[i] = (c - '0');
    }   
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        if (!f[i])
            continue;
        dfs (i);
        for (int j : g[i]) {
            mx = max(mx, dp[j] + 1); 
        }
    }   
    cout << mx; 
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -