# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
518426 | Vladth11 | Power Plant (JOI20_power) | C++14 | 175 ms | 32328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 200001;
const ll VMAX = 21;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 60;
vector <int> v[NMAX];
string s;
int dp[NMAX][2];
void DFS(int node, int p){
if(s[node - 1] == '1'){
dp[node][1] = 1;
}
int maxim = -2e9, maxim1 = -2e9, maxim2 = 0, sum = 0;
for(auto x : v[node]){
if(x == p)
continue;
DFS(x, node);
maxim = max(maxim, dp[x][2]);
maxim1 = max(maxim1, dp[x][1]);
sum += dp[x][1];
}
dp[node][2] = maxim;
dp[node][2] = max(dp[node][2], maxim1 + (s[node - 1] == '1')); /// il iau pe cel mai de sus
dp[node][1] = max(dp[node][1], sum - (s[node - 1] == '1'));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, i;
cin >> n;
for(i = 1; i < n; i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
cin >> s;
DFS(1, 0);
cout << max(dp[1][1], dp[1][2]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |