Submission #293160

#TimeUsernameProblemLanguageResultExecution timeMemory
293160CaroLindaPower Plant (JOI20_power)C++14
0 / 100
4 ms4992 KiB
#include <bits/stdc++.h> #define pb push_back #define ll long long #define pii pair<int,int> #define mk make_pair #define all(x) x.begin(),x.end() #define ff first #define ss second #define debug printf #define lp(i,a,b) for(int i = a ; i < b ; i++ ) #define sz(x) (int)(x.size()) const int MAXN = 2e5+10 ; using namespace std ; int N ; int dp[MAXN][2] ; vector<int> adj[MAXN] ; bool isPower[MAXN] ; char str[MAXN] ; void dfs(int x, int dad) { int mx[2] = {0,0} ; int soma1 = 0 ; for(auto e : adj[x] ) { if(e == dad) continue ; dfs(e,x) ; lp(i,0,2) mx[i] = max(mx[i] , dp[e][i]) ; soma1 += dp[e][1] ; } if(!isPower[x]) { dp[x][0] = max( soma1, mx[0] ) ; dp[x][1] = soma1 ; } else { dp[x][0] = max( mx[1] + 1 , soma1 - 1 ) ; dp[x][1] = max( 1 , soma1 - 1 ) ; } } int main() { scanf("%d", &N) ; for(int i = 1 , u ,v ; i < N ; i++ ) { scanf("%d%d", &u, &v ) ; adj[u].pb(v) ; adj[v].pb(u) ; } scanf("%s", str ) ; lp(i,0,N) isPower[i+1] = ( str[i] == '1' ) ; dfs(1,-1) ; printf("%d\n" , dp[1][0]) ; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |     scanf("%d", &N) ;
      |     ~~~~~^~~~~~~~~~
power.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |         scanf("%d%d", &u, &v ) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~
power.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |     scanf("%s", str ) ;
      |     ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...