Submission #588761

#TimeUsernameProblemLanguageResultExecution timeMemory
588761Loki_NguyenPower Plant (JOI20_power)C++14
100 / 100
161 ms31668 KiB
#include <bits/stdc++.h> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define task "test" #define pii pair<pll, pll> using namespace std; using ll = int; const int N = 2e5+5; const ll mod = 1e8 + 7; const ll base = 113; const ll inf = 1e9; int m, n, t, k, a[N], tong, d[N], dp[N], h[N], ans; vector<int> adj[N]; string s; int dfs(int u, int p = 0) { if(dp[u] != -1)return dp[u]; int sum = 0, cnt = 0, mx = 0; for(int v: adj[u]) { if(v == p)continue; sum += dfs(v, u); mx = max(mx, dfs(v, u)); ++cnt; } if(s[u] == '1') { ans = max(ans, mx+1); sum = max(sum-1, 1); } ans = max(ans, sum); return dp[u] = sum; } void sol() { cin >> n; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } cin >> s; s = " " + s; fill_n(dp, n+1, -1); dfs(1); cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } int ntest = 1; // cin >> ntest; while (ntest-- > 0) sol(); }

Compilation message (stderr)

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