Submission #312776

# Submission time Handle Problem Language Result Execution time Memory
312776 2020-10-14T10:47:34 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;
ll ans =  0;
int snd;
ll dfs(int nd, int ss){
    ll r = '0'-s[nd];
    if(v[nd].size() <= 2 && s[nd] == '1') r = 1;
    for(int x: v[nd]) if(x != ss){
        ll y =dfs(x, nd);
        ans = max(y, ans);
        y--;
        y - max(y, (ll)s[nd]-'0');
        r+=y;
    }
    return max(r, (ll)s[nd] - '0');
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    v = vector<vector<int>> (n+1);
    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;
    ans = max(ans, dfs(1, -1));
    cout << ans << "\n";
}

Compilation message

power.cpp: In function 'll dfs(int, int)':
power.cpp:20:11: warning: value computed is not used [-Wunused-value]
   20 |         y - max(y, (ll)s[nd]-'0');
      |         ~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -