Submission #868665

#TimeUsernameProblemLanguageResultExecution timeMemory
868665prohackerPower Plant (JOI20_power)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 5010; const int INF = INT_MAX; const int mod = 1e9+7; int n,ans,dp[N]; vector<int> adj[N]; string s; void dfs(int u, int pre) { dp[u] = 0; int res = 0; for(int v:adj[u]) { if(v == pre) { continue; } dfs(v,u); res += dp[v]; } dp[u] = max(res-(s[u] == '1'),(s[u] == '1' ? 1 : 0)); if(pre == 0) { int cnt = 0; for(int v:adj[u]) { if(dp[v]) { cnt++; } } if(cnt < 2) { dp[u]++; } ans = max(ans,dp[u]); } } signed main() { if (fopen("power.inp", "r")) { freopen("power.inp", "r", stdin); freopen("power.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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; for(int i = 1 ; i <= n ; i++) { if(s[i] == '1') { dfs(i,0); } } cout << ans; return 0; }

Compilation message (stderr)

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