Submission #493636

#TimeUsernameProblemLanguageResultExecution timeMemory
493636600MihneaPower Plant (JOI20_power)C++17
0 / 100
4 ms5068 KiB
#include <bits/stdc++.h> using namespace std; const int N = (int) 2e5 + 7; int n; int sol; int dp[N]; int is[N]; vector<int> g[N]; string s; void build(int a, int p = -1) { dp[a] = 0; for (auto &b : g[a]) { if (b != p) { build(b, a); dp[a] += dp[b]; } } dp[a] -= is[a]; dp[a] = max(dp[a], is[a]); } int main() { ios::sync_with_stdio(0); cin.tie(0); freopen ("input.txt", "r", stdin); cin >> n; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } cin >> s; int cnt = 0; for (int i = 1; i <= n; i++) { is[i] = s[i - 1] - '0'; cnt += is[i]; } sol = min(cnt, 2); for (int i = 1; i <= n; i++) { build(i); sol = max(sol, dp[i]); } cout << sol << "\n"; return 0; }

Compilation message (stderr)

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