Submission #467869

#TimeUsernameProblemLanguageResultExecution timeMemory
467869stefantagaPower Plant (JOI20_power)C++14
0 / 100
3 ms5068 KiB
#include <bits/stdc++.h> using namespace std; vector <int> v[200005]; int din[200005][2],val[200005]; void dfs(int x,int tata) { int ok=0,i; for (i=0;i<v[x].size();i++) { if (v[x][i]!=tata) { ok=1; dfs(v[x][i],x); } } if (ok==0) { if (val[x]==1) { din[x][1]=1; din[x][0]=1; } } else { if (x==1&&v[x].size()==1) { din[x][1]=max(din[v[x][0]][0]+1,din[v[x][0]][1]+1); din[x][0]=1; } else { if (val[x]==0) { for (i=0;i<v[x].size();i++) { din[x][0]=din[x][0]+max(din[v[x][i]][0],din[v[x][i]][1]); } } else { int sum1=0,sum0=0; for (i=0;i<v[x].size();i++) { int nod=v[x][i]; sum1=sum1+max(din[nod][1],din[nod][0]); } din[x][1]=sum1-1; din[x][0]=1; } } } } int n,i,x,y; char ch; int main() { ios_base :: sync_with_stdio(false); cin.tie(0); #ifdef HOME ifstream cin("date.in"); ofstream cout("date.out"); #endif // HOME cin>>n; for (i=1;i<=n-1;i++) { cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } for (i=1;i<=n;i++) { cin>>ch; val[i]=ch-'0'; } dfs(1,0); /*for (i=1;i<=n;i++) { cout<<i<<" "<<din[i][0]<<" "<<din[i][1]<<'\n'; }*/ cout<<max(din[1][0],din[1][1]); return 0; }

Compilation message (stderr)

power.cpp: In function 'void dfs(int, int)':
power.cpp:9:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (i=0;i<v[x].size();i++)
      |              ~^~~~~~~~~~~~
power.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for (i=0;i<v[x].size();i++)
      |                      ~^~~~~~~~~~~~
power.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             for (i=0;i<v[x].size();i++)
      |                      ~^~~~~~~~~~~~
power.cpp:43:24: warning: unused variable 'sum0' [-Wunused-variable]
   43 |             int sum1=0,sum0=0;
      |                        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...