Submission #818419

#TimeUsernameProblemLanguageResultExecution timeMemory
818419vjudge1Power Plant (JOI20_power)C++17
100 / 100
199 ms37000 KiB
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define fi first #define se second #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 5e5 + 9 , mod = 1e9 + 7; ll d[N] , a[N] = {}, dp[N] , b[N] , c[N]; vector<int>v[N]; void dfs(int n , int p = 0){ for(auto to : v[n]) if(to != p) dfs(to , n); for(auto to : v[n]) if(to != p) if(dp[to] + b[n] >= c[n]) c[n] = dp[to] + b[n]; dp[n] -= b[n]; dp[n] = max(dp[n] , b[n]); dp[p] += dp[n]; } void solve(){ ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n; for(i = 1; i < n; i++){ cin>>l>>r; v[l].pb(r); v[r].pb(l); } string a; cin>>a; for(i = 1; i <= n; i++) b[i] = (a[i - 1] == '1'); dfs(1); for(i = 1; i <= n; i++) mx = max({mx , c[i] , dp[i]}); cout<<mx<<"\n"; } int main(){ /* TL; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن

Compilation message (stderr)

power.cpp: In function 'void solve()':
power.cpp:42:8: warning: unused variable 'q' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
power.cpp:42:16: warning: unused variable 'j' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                ^
power.cpp:42:20: warning: unused variable 'm' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                    ^
power.cpp:42:26: warning: unused variable 'z' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
power.cpp:42:29: warning: unused variable 's' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                             ^
power.cpp:42:37: warning: unused variable 'f' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                     ^
power.cpp:42:49: warning: unused variable 'k' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                 ^
power.cpp:42:53: warning: unused variable 'x' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                     ^
power.cpp:42:57: warning: unused variable 'y' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                         ^
power.cpp:42:61: warning: unused variable 'mn' [-Wunused-variable]
   42 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...