Submission #859791

#TimeUsernameProblemLanguageResultExecution timeMemory
859791mgl_diamondPower Plant (JOI20_power)C++17
100 / 100
92 ms29584 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; #define foru(i, l, r) for(int i=(l); i<=(r); ++i) #define ford(i, l, r) for(int i=(l); i>=(r); --i) #define fore(x, v) for(auto &x : v) #define all(x) (x).begin(), (x).end() #define sz(x) (int)x.size() void setIO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("input.inp", "r")) { freopen("input.inp", "r", stdin); freopen("input.out", "w", stdout); } } const int N = 2e5+5; int n, m, e[N]; string s; vector<int> tree[N]; int ans, dp[N]; void dfs(int u, int p) { dp[u] = e[u]; int sum = 0, ma = 0; fore(v, tree[u]) if (v != p) { dfs(v, u); sum += dp[v]; ma = max(ma, dp[v]); } dp[u] = max(dp[u], sum - e[u]); ans = max(ans, max(sum - e[u], ma + e[u])); } int main() { setIO(); cin >> n; foru(i, 2, n) { int u, v; cin >> u >> v; tree[u].push_back(v); tree[v].push_back(u); } cin >> s; foru(i, 1, n) e[i] = (s[i-1] == '1'); dfs(1, 0); cout << ans; }

Compilation message (stderr)

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