Submission #955873

# Submission time Handle Problem Language Result Execution time Memory
955873 2024-03-31T15:54:14 Z vjudge1 Power Plant (JOI20_power) C++17
0 / 100
3 ms 7608 KB
#include<bits/stdc++.h>
using namespace std;
int n;
int x,y;
vector<int>a[300000];
int f[300000];
int k[300000];
string s;
int asw=0;
void sol(int i,int c){
    int mx=0;
    for(int u:a[i]){
        if(u!=c){
            sol(u,i);
            f[i]+=f[u];
            mx=max(mx,f[u]);
        }
    }
    if(s[i]=='1'){
        asw=max(asw,mx+1);
        f[i]=max(f[i],1);
    }
    if(s[i]=='1'&&i!=1&&a[i].size()==1)f[i]=1;
}
int main(){
    cin >>n;
    for(int i=1;i<n;i++){
        cin >>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    cin >>s;
    s=" "+s;
    sol(1,1);
    cout <<max(asw,f[1]);
}
/*
5
1 2
2 3
2 4
2 5
11111
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7608 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Incorrect 2 ms 7516 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7608 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Incorrect 2 ms 7516 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7608 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Incorrect 2 ms 7516 KB Output isn't correct
6 Halted 0 ms 0 KB -