Submission #558075

#TimeUsernameProblemLanguageResultExecution timeMemory
558075groshiPower Plant (JOI20_power)C++17
100 / 100
172 ms25452 KiB
#include<iostream> #include<vector> using namespace std; struct wi{ vector<int> Q; }*w; int wynik=0; string s; int dfs(int x,int ojc) { int ile=0; for(int i=0;i<w[x].Q.size();i++) { int pom=w[x].Q[i]; if(pom==ojc) continue; int k=dfs(pom,x); ile+=k; if(s[x-1]=='1') wynik=max(wynik,k+1); } if(s[x-1]=='1') ile=max(ile-1,1); wynik=max(wynik,ile); return ile; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n,x,y; cin>>n; w=new wi[n+3]; for(int i=1;i<n;i++) { cin>>x>>y; w[x].Q.push_back(y); w[y].Q.push_back(x); } cin>>s; int k=dfs(1,0); cout<<wynik; return 0; }

Compilation message (stderr)

power.cpp: In function 'int dfs(int, int)':
power.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
power.cpp: In function 'int main()':
power.cpp:42:9: warning: unused variable 'k' [-Wunused-variable]
   42 |     int k=dfs(1,0);
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...