Submission #401093

#TimeUsernameProblemLanguageResultExecution timeMemory
401093cpp219Power Plant (JOI20_power)C++14
100 / 100
167 ms27520 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 6; const ll Log2 = 19; const ll inf = 1e9 + 7; typedef pair<ll,ll> LL; string s; ll n,x,y,a[N],mx[N],ans = 1; vector<ll> g[N]; void DFS(ll u,ll p){ mx[u] = a[u]; for (auto i : g[u]) if (i != p) DFS(i,u); ll cur = -a[u],mxchild = 0; for (auto i : g[u]) if (mx[i] > 0 && i != p) cur += mx[i],mxchild = max(mxchild,mx[i]); mx[u] = max(mx[u],cur); ans = max(ans,max(mx[u],mxchild + a[u])); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n; for (ll i = 1;i < n;i++){ cin>>x>>y; g[x].push_back(y); g[y].push_back(x); } cin>>s; for (ll i = 0;i < n;i++) a[i + 1] = s[i] - '0'; DFS(1,0); //cout<<mx[3]; return 0; cout<<ans; }

Compilation message (stderr)

power.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
power.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
power.cpp: In function 'int main()':
power.cpp:43:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   43 |     for (ll i = 0;i < n;i++) a[i + 1] = s[i] - '0'; DFS(1,0);
      |     ^~~
power.cpp:43:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   43 |     for (ll i = 0;i < n;i++) a[i + 1] = s[i] - '0'; DFS(1,0);
      |                                                     ^~~
power.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...