Submission #536357

#TimeUsernameProblemLanguageResultExecution timeMemory
536357MonarchuwuPower Plant (JOI20_power)C++17
100 / 100
177 ms34808 KiB
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long ll; const int N = 2e5 + 8; int n, a[N]; char s[N]; vector<int> g[N]; void upd(int &a, int b) { if (a < b) a = b; } int dp[N], cnt[N][3], tmp[4]; int ans; void dfs(int u, int p) { for (int v : g[u]) if (v != p) { dfs(v, u); if (u == 2) { int bug = 1; } fill(tmp, tmp + 4, 0); for (int i = 0; i < 3; ++i) upd(tmp[i + 1], cnt[u][i] + dp[v]); upd(cnt[u][1], tmp[1]); upd(cnt[u][2], tmp[2]); upd(cnt[u][2], tmp[3]); } dp[u] = max({ a[u], cnt[u][1] - a[u], cnt[u][2] - a[u] }); ans = max({ ans, cnt[u][1] + a[u], cnt[u][2] - a[u] }); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin >> n; for (int i = 1, u, v; i < n; ++i) { cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cin >> (s + 1); for (int i = 1; i <= n; ++i) a[i] = s[i] ^ 48; dfs(1, 0); cout << ans << '\n'; } /** /\_/\ * (= ._.) * / >0 \>1 **/

Compilation message (stderr)

power.cpp: In function 'void dfs(int, int)':
power.cpp:20:17: warning: unused variable 'bug' [-Wunused-variable]
   20 |             int bug = 1;
      |                 ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...