# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530316 | kevin | Power Plant (JOI20_power) | C++17 | 142 ms | 28528 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>
using namespace std;
#define ll long long
#define nl cout<<"\n"
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
vector<int> adj[MAXN];
int ar[MAXN];
int mx = 0;
int dfs(int x, int p){
int sm = 0;
for(int i:adj[x]){
if(i == p) continue;
int val = dfs(i, x);
sm += val;
if(ar[x]) mx = max(mx, 1 + val);
}
if(ar[x]) {
// cout<<x+1<<" "<<max(sm-1, 1)<<"\n";
mx = max(mx, sm - 1);
return max(sm-1, 1);
}
// cout<<x+1<<" "<<sm<<"\n";
mx = max(mx, sm);
return sm;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
int n;
cin>>n;
for(int i=0; i<n-1; i++){
int u, v; cin>>u>>v;
adj[--u].push_back(--v);
adj[v].push_back(u);
}
for(int i=0; i<n; i++){
char c; cin>>c;
ar[i] = c == '1';
if(ar[i]) mx = 1;
}
dfs(0, -1);
cout<<mx;
}
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... |