Submission #320589

#TimeUsernameProblemLanguageResultExecution timeMemory
320589achibasadzishviliPower Plant (JOI20_power)C++14
100 / 100
217 ms37864 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll dp[300005][2],n,c[300005]; vector<ll>v[300005]; void go(ll x,ll par){ ll mx0 = 0,mx1 = 0,sum0 = 0,sum1 = 0; for(int i=0; i<v[x].size(); i++){ int to = v[x][i]; if(to == par)continue; go(to , x); mx0 = max(mx0 , dp[to][0]); sum0 += dp[to][0]; sum1 += dp[to][1]; mx1 = max(mx1 , dp[to][1]); } mx0 = max(mx0 , c[x] + mx1); dp[x][0] = mx0; dp[x][1] = max(c[x] , sum1 - c[x]); } int main(){ ios::sync_with_stdio(false); cin >> n; for(int i=1; i<n; i++){ ll x,y; cin >> x >> y; v[x].pb(y); v[y].pb(x); } for(int i=1; i<=n; i++){ char x; cin >> x; c[i] = (x == '1'); } go(1 , 0); cout << max(dp[1][0] , dp[1][1]) << '\n'; return 0; }

Compilation message (stderr)

power.cpp: In function 'void go(long long int, long long int)':
power.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0; i<v[x].size(); i++){
      |                  ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...