Submission #293364

#TimeUsernameProblemLanguageResultExecution timeMemory
293364GajowyPower Plant (JOI20_power)C++14
100 / 100
258 ms28856 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define mp make_pair #define eb emplace_back #define pb push_back #define e1 first #define e2 second #define int int_fast32_t #define uint uint_fast64_t #define ll int_fast64_t #define ull uint_fast64_t #define int16 int_fast16_t #define uint16 uint_fast16_t #define int32 int_fast32_t #define uint32 uint_fast32_t #define int64 int_fast64_t #define uint64 uint_fast64_t #define ld long double #define float long double #define size(x) (int)x.size() #define satori int testCases; cin>>testCases; while(testCases--) #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define all(r) begin(r),end(r) #define rall(r) rbegin(r),rend(r) #define time chrono::high_resolution_clock().now().time_since_epoch().count() #define elapsed(__begin,__end) (__end-__begin)/CLOCKS_PER_SEC typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; float pi=3.14159265358979323846; const int MAXN=2e5+10; int dp[MAXN],dp2[MAXN],pp[MAXN],pr[MAXN]; vector<int> g[MAXN]; string s; void dfs(int u,int p) { pr[u]=p; dp[u]=pp[u]; int sm=-pp[u]; for(auto v:g[u]) if(v!=p) dfs(v,u),sm+=dp[v]; dp[u]=max(dp[u],sm); } void dfs2(int u,int p) { int sm=dp2[u]; for(auto v:g[u]) if(v!=p) sm+=dp[v]; for(auto v:g[u]) if(v!=p) dp2[v]=max(pp[u],sm-dp[v]-pp[u]),dfs2(v,u); } int32_t main() { fastio; int n,u,v,res=0; cin>>n; for(int i=1;i<n;i++) cin>>u>>v,g[u].eb(v),g[v].eb(u); cin>>s; for(int i=0;i<n;i++) pp[i+1]=(int)(s[i]-'0'); dfs(1,0); dfs2(1,0); for(int i=1;i<=n;i++) { res=max(res,dp[i]+dp2[i]); for(auto vv:g[i]) if(vv!=pr[i]) res=max(res,pp[i]+dp[vv]); } cout<<res<<'\n'; }

Compilation message (stderr)

power.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
power.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...