Submission #312731

# Submission time Handle Problem Language Result Execution time Memory
312731 2020-10-14T09:07:59 Z Jarif_Rahman Power Plant (JOI20_power) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n;
str s;
vector <vector<int>> v;
vector <ll> sth, root;
ll ans =  0;
ll dfs1(int nd, int ss){
    ll r = '0'-s[nd];
    if(v[nd].size() == 1 && s[nd] == '1') r = 1;
    for(int x: v[nd]) if(x != ss) r+=dfs1(x, nd);
    sth[nd] = max(r, (ll)s[nd] - '0');
    return sth[nd];
}
void dfs2(int nd, int ss, ll cur){
    for(int x: v[nd]) if(x != ss) cur+=sth[x];
    for(int x: v[nd]) if(x != ss){
        ll cc = cur;
        cc-=sth[x];
        cc = max(cc, (ll)s[nd] - '0');
        root[x] += cc;
        dfs2(x, nd, cc + '0' - s[x]);
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    v = vector<vector<int>> (n+1);
    sth = vector <ll> (n+1, -1);
    root = vector<ll> (n+1, 0);
    for(int i = 1; i < n; i++){
        int a, b; cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin >> s;
    s = "x"+s;
    dfs1(1, -1);
    for(int i = 1; i <= n; i++) root[i] = sth[i];
    dfs2(1, -1, s[1] - '0');
 	for(int i = 1; i <= n; i++) ans = max(ans, root[i]);
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -