Submission #1286851

#TimeUsernameProblemLanguageResultExecution timeMemory
1286851adscodingPower Plant (JOI20_power)C++20
100 / 100
148 ms28672 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define BIT(mask, x) ((mask >> (x)) & 1) #define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; // -------------------------------------- CON CUA BO HCN -------------------------------------- const int maxn = 2e5 + 3; int n, dp[maxn], res; bitset<maxn> has; vector<int> g[maxn]; // -------------------------------------------------------------------------------------------- void dfs(int u, int p) { for (int v : g[u]) { if (v == p) continue; dfs(v, u); if (has[u]) res = max(res, dp[v] + 1); dp[u] += dp[v]; } if (has[u]) dp[u] = max(dp[u] - 1, (int)has[u]); res = max(res, dp[u]); } void solve() { cin >> n; FOR(i, 2, n) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } FOR(i, 1, n) { char op; cin >> op; has[i] = op - '0'; } dfs(1, -1); cout << res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define TASK "TEST" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); return 0; } /* NOTES: */

Compilation message (stderr)

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