Submission #516479

#TimeUsernameProblemLanguageResultExecution timeMemory
516479DJ035Power Plant (JOI20_power)C++17
0 / 100
2 ms3788 KiB
#include <bits/stdc++.h> #define MEM 111111 #define sanic ios_base::sync_with_stdio(0) #define x first #define y second #define pf push_front #define pb push_back #define all(v) v.begin(), v.end() #define sz size() using namespace std; typedef long long ll; typedef pair<ll, ll> pi; const ll MOD = 1e9+7; const ll INF = 2e14+7; ll mul(ll a, ll b){ return ((a*b)%MOD+MOD)%MOD; } ll add(ll a, ll b){ return ((a+b)%MOD+MOD)%MOD; } ll t,n,m,q,k; ll dp[MEM]; ll ans; vector<ll> g[MEM]; string s; ll DP(ll c, ll p){ ll& ret = dp[c]; if(ret!=-1) return ret; ll dsum=0, dmx=-INF; for(ll nt:g[c]){ if(nt==p) continue; ll o=DP(nt, c); dsum += o; dmx = max(o, dmx); } ll ct=(ll)(s[c-1]-'0'); ret = max(dsum-ct, ct); ans = max({ans, dmx+ct, dsum-ct}); return ret; } signed main(){ sanic; cin.tie(0); cout.tie(0); memset(dp, -1, sizeof(dp)); cin >> n; for(int i=1; i<n; i++){ ll q1,q2; cin >> q1 >> q2; g[q1].pb(q2); g[q2].pb(q1); } cin >> s; DP(1, -1); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...