Submission #423332

#TimeUsernameProblemLanguageResultExecution timeMemory
423332DanerZeinPower Plant (JOI20_power)C++14
47 / 100
1604 ms14432 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; vector<vi> G; string x; int dfs(int u,int p){ int ans=0; for(auto &v:G[u]){ if(v!=p){ ans+=dfs(v,u); } } int mi=0; if(x[u]=='1') mi=1; return max(ans-mi,mi); } int main(){ int n; cin>>n; G.resize(n+1); for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } cin>>x; int c=0; for(int i=0;i<x.size();i++){ if(x[i]=='1') c++; } int ans=min(c,2); for(int i=0;i<n;i++){ int rp=dfs(i,-1); ans=max(ans,rp); } cout<<ans<<endl; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i=0;i<x.size();i++){
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...