Submission #1250755

#TimeUsernameProblemLanguageResultExecution timeMemory
1250755wedonttalkanymorePower Plant (JOI20_power)C++20
100 / 100
106 ms27072 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define pii pair<ll, ll> #define fi first #define se second const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 1 << 16; int n; vector <int> adj[N]; int dp[N]; string s; int ans = 0; void dfs(int u, int par) { // dp[u] = (s[u] == '1'); int maxx = 0, sum = 0; for (auto v : adj[u]) { if (v == par) continue; dfs(v, u); maxx = max(maxx, dp[v]); sum += dp[v]; } dp[u] = sum; // cout << u << ' ' << sum << ' ' << maxx << '\n'; if (s[u] == '1') dp[u] = max(dp[u] - 1, 1LL); // sum la tong dp cua cac con ans = max({ans, dp[u], maxx + (s[u] == '1')}); // chon them con u } signed main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } cin >> s; s = "#" + s; dfs(1, 0); // for (int i = 1; i <= n; i++) cout << dp[i] << ' '; // cout << '\n'; cout << ans; return 0; }

Compilation message (stderr)

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