제출 #1140497

#제출 시각아이디문제언어결과실행 시간메모리
1140497browntoadPower Plant (JOI20_power)C++20
0 / 100
3 ms6464 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, n+1) #define pii pair<int, int> #define f first #define s second #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int)((x).size()) #define pb push_back #define endl '\n' #define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); const ll maxn = 2e5+5; const ll inf = 1ll<<60; const ll mod = 1e9+7; int n; int ans = 0; vector<int> dp(maxn); vector<int> g[maxn]; vector<bool> c(maxn); void dfs(int x, int pre){ int tp = (x > 1 && c[pre]); for (auto y:g[x]){ if (y == pre) continue; dfs(y, x); dp[x] += max((int)(c[y]), dp[y]); } dp[x] -= c[x]; ans = max(ans, dp[x]+tp); } signed main(){ IOS(); cin>>n; REP(i, n-1){ int u, v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } string str; cin>>str; str = '$'+str; REP1(i, n) c[i] = (str[i] == '1'); dfs(1, -1); cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...