Submission #1221944

#TimeUsernameProblemLanguageResultExecution timeMemory
1221944minggaPower Plant (JOI20_power)C++20
100 / 100
70 ms26692 KiB
#include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define int long long const int mod = 1e9 + 7; const int inf = 2e18; const int N = 2e5 + 7; int n; vector<int> g[N]; bool a[N]; int dp[N], ans; void dfs(int u, int p) { int mx = 0; for(int v : g[u]) { if(v == p) continue; dfs(v, u); dp[u] += dp[v]; mx = max(mx, dp[v]); } if(a[u]) dp[u] = max(dp[u] - 1, 1ll); ans = max({ans, dp[u], mx + a[u]}); } signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } for(int i = 1; i <= n; i++) { char c; cin >> c; if(c == '1') a[i] = 1; } dfs(1, 0); cout << ans << ln; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:37:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
power.cpp:38:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...