Submission #546179

#TimeUsernameProblemLanguageResultExecution timeMemory
546179DeepessonPower Plant (JOI20_power)C++17
0 / 100
4 ms5088 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...