Submission #1261382

#TimeUsernameProblemLanguageResultExecution timeMemory
1261382Bui_Quoc_CuongPower Plant (JOI20_power)C++20
100 / 100
119 ms26436 KiB
#include <bits/stdc++.h> using namespace std; template <class A, class B> bool maximize(A &a, const B b) { if (a < b) { a = b; return true; } return false; } template <class A, class B> bool minimize(A &a, const B b) { if (a > b) { a = b; return true; } return false; } #define pb push_back #define FOR(i, a, b) for(int i = a; i <= (int)b; i++) #define FORD(i, a, b) for(int i = a; i >= (int)b; i--) #define fi first #define se second #define ALL(A) A.begin(), A.end() typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; const int N = 3e5 + 5; const int oo = 2e9 + 29032008; const ll INF = 1e18 + 29032008; int n; vi g[N]; int s[N]; int dp[N], ans = 0; void dfs(int u, int p) { for (int &v : g[u]) if (v != p) { dfs(v, u); dp[u]+= dp[v]; maximize(ans, dp[v] + s[u]); } dp[u] = max(dp[u] - s[u], s[u]); ans = max(ans, dp[u]); } void solve() { cin >> n; FOR(i, 1, n - 1) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } FOR(i, 1, n) { char c; cin >> c; s[i] = c - '0'; } dfs(1, 1); cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #define ko "kieuoanh" if (fopen(ko".inp", "r")) { freopen(ko".inp", "r", stdin); // freopen(ko".out", "w", stdout); } int NTEST = 1; // cin >> NTEST; while (NTEST--) solve(); cerr << "\n[Time Elapsed] " << 0.001 * clock() << "s\n"; return 0; }

Compilation message (stderr)

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