Submission #298516

# Submission time Handle Problem Language Result Execution time Memory
298516 2020-09-13T04:06:15 Z BeanZ Power Plant (JOI20_power) C++14
0 / 100
4 ms 4992 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl '\n'
const int N = 2e5 + 5;
ll dp[N], cur[N];
vector<ll> node[N];
string s;
ll ans = 0;
void dfs(ll u, ll p){
        vector<ll> val;
        for (auto j : node[u]){
                if (j == p) continue;
                dfs(j, u);
                val.push_back(dp[j]);
        }
        if (val.size()){
                sort(val.begin(), val.end(), greater<ll>());
                ans = max(ans, val[0] + (s[u] == '1'));
                ll sum = 0;
                for (auto j : val) sum += j;
                ans = max(ans, sum - (s[u] == '1'));
                dp[u] = max((ll)(s[u] == '1'), sum - (s[u] == '1'));
        } else {
                dp[u] = (s[u] == '1');
        }
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("A.INP", "r")){
                freopen("A.INP", "r", stdin);
                freopen("A.OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        for (int i = 1; i < n; i++){
                ll u, v;
                cin >> u >> v;
                node[u].push_back(v);
                node[v].push_back(u);
        }
        cin >> s;
        s = " " + s;
        dfs(1, 1);
        cout << ans;
}
/*
*/

Compilation message

power.cpp: In function 'int main()':
power.cpp:34:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |                 freopen("A.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
power.cpp:35:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |                 freopen("A.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -