Submission #546179

# Submission time Handle Problem Language Result Execution time Memory
546179 2022-04-06T15:19:59 Z Deepesson Power Plant (JOI20_power) C++17
0 / 100
4 ms 5088 KB
#include <bits/stdc++.h>
#define MAX 205000
std::vector<int> con[MAX];
std::string valores;
typedef std::pair<int,int> pii;
std::map<pii,int> mapa;

int explora(int pos,int prev){
    pii cod = {pos,prev};
    if(mapa.find(cod)!=mapa.end())return mapa[cod];
    int ans=0;
    if(valores[pos]=='1')ans=1;
    int soma=0;
    for(auto&x:con[pos]){
        if(x==prev)continue;
        soma+=explora(x,pos);
    }
    if(valores[pos]=='1')--soma;
    mapa[cod]=std::max(ans,soma);
    return std::max(ans,soma);
}

int N;
int ans=0;
int main()
{
    std::cin>>N;
    for(int i=1;i!=N;++i){
        int a,b;
        std::cin>>a>>b;
        --a;--b;
        con[a].push_back(b);
        con[b].push_back(a);
    }
    std::cin>>valores;
    for(int i=0;i!=N;++i){
        int tot=0;
        for(auto&x:con[i]){
            tot+=explora(x,i);
        }
        if(valores[i]=='1'){
            --tot;
            tot=std::max(tot,1);
        }
        ans=std::max(ans,tot);
    }
    std::cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5088 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Incorrect 3 ms 5076 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5088 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Incorrect 3 ms 5076 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5088 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Incorrect 3 ms 5076 KB Output isn't correct
9 Halted 0 ms 0 KB -