답안 #546181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546181 2022-04-06T15:21:24 Z Deepesson Power Plant (JOI20_power) C++17
0 / 100
3 ms 5084 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);
    }
    assert(ans);
    std::cout<<ans<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 2 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5084 KB Output is correct
6 Correct 3 ms 5076 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 2 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5084 KB Output is correct
6 Correct 3 ms 5076 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 2 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5084 KB Output is correct
6 Correct 3 ms 5076 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 -