Submission #788015

# Submission time Handle Problem Language Result Execution time Memory
788015 2023-07-19T16:15:07 Z YassineBenYounes Power Plant (JOI20_power) C++17
0 / 100
4 ms 7308 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define vii vector<pii>
void init(){
    #ifndef ONLINE_JUDGE
 
freopen("input.txt", "r", stdin);
 
freopen("output.txt", "w", stdout);
 
#endif // ONLINE_JUDGE
}

const int mx = 3e5+5;
const ll mod = 1e9+7;

vector<int> graph[mx];
string s;

int dp_down[mx];

int ans = 0;

void dfs(int node, int p){
    int l = 0, sum = 0;
    for(int adj : graph[node]){
        if(adj == p)continue;
        dfs(adj ,node);
        sum += dp_down[adj];
        l = max(l, dp_down[adj]);
    }
    int k = (s[node] == '1');
    sum -= k;
    dp_down[node] = max(dp_down[node], k);
    dp_down[node] = max(dp_down[node], sum);
    ans = max(ans, l+k);
    ans = max(ans, dp_down[node]);
}

void runcase(){
    int n;cin >> n;
    for(int i = 0; i < n-1;i++){
        int a, b;cin >> a >> b;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    cin >> s;
    s = "Y" + s;
    dfs(1, 1);
    cout << ans << endl;
}

int main(){
    init();
    int t;
    //cin >> t;
    t = 1;
    while(t--){
        runcase();
    }
}

Compilation message

power.cpp: In function 'void init()':
power.cpp:14:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
power.cpp:16:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7308 KB Output isn't correct
2 Halted 0 ms 0 KB -