Submission #1020211

#TimeUsernameProblemLanguageResultExecution timeMemory
1020211cpptowinPower Plant (JOI20_power)C++17
100 / 100
125 ms49748 KiB
#include<bits/stdc++.h> #define fo(i,l,r) for(int i = l ; i <= r ; i ++) #define fod(i,r,l) for(int i = r ; i >= l ; i--) #define pb emplace_back #define int long long #define maxn 1000010 #define N 1010 #define inf (int)1e18 #define bitcount(x) __builtint_popcount(x) #define bit(x,i) ((x >> i) & 1) #define onbit(x,i) (x | (1ll << i)) #define offbit(x,i) (x ^ (1ll << i)) #define lb(x) x & -x #define all(x) x.begin(),x.end() #define ss(x) (int)x.size() #define en cout << "\n"; #define vi vector<int> #define pii pair<int,int> #define vii vector<pii> using namespace std; bool maximize(int &a,int b) { if(a <= b) { a = b; return 1; } return 0; } bool minimize(int &a,int b) { if(a >= b) { a = b; return 1; } return 0; } int n,a[maxn],f[maxn]; vi ke[maxn]; int ans = 0; void dfs(int u,int par = 0) { int sum = 0,maxx = 0; for(int v : ke[u]) if(v != par) { dfs(v,u); maximize(maxx,f[v]); sum += f[v]; } if(a[u]) { maximize(ans,maxx + 1); maximize(ans,sum - 1); } else maximize(ans,sum); f[u] = max(a[u],sum - a[u]); } main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; fo(i,1,n - 1) { int u,v; cin >> u >> v; ke[u].pb(v); ke[v].pb(u); } fo(i,1,n) { char t; cin >> t; a[i] = t - '0'; } dfs(1); cout << ans; }

Compilation message (stderr)

power.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main()
      | ^~~~
power.cpp: In function 'int main()':
power.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
power.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...