Submission #427589

# Submission time Handle Problem Language Result Execution time Memory
427589 2021-06-14T17:31:02 Z davi_bart Power Plant (JOI20_power) C++17
0 / 100
4 ms 4940 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
int N;
string c;
vector<int> v[200010];
pair<int,int> ans(int pos,int prec){
    vector<pair<int,int> > k;
    for(int x:v[pos]){
        if(x==prec)continue;
        k.pb(ans(x,pos));
    }
    pair<int,int> ma={0,0};//at most 1 in line,most 2 in line
    if(c[pos]=='1'){
        for(auto [a,b]:k){
            ma.fi+=a;
            ma.se=max(ma.se,a+1);
        }
        ma.fi--;
        ma.fi=max(ma.fi,(int)1);
    }else{
        for(auto [a,b]:k){
            ma.fi+=a;
            ma.se=max(ma.se,b);
        }
    }
    //cout<<pos<<" "<<ma.fi<<" "<<ma.se<<endl;
    return ma;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin>>c;
    auto k=ans(0,-1);
    cout<<max(k.fi,k.se)<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4900 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4900 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4900 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -