Submission #945959

#TimeUsernameProblemLanguageResultExecution timeMemory
945959efedmrlrPower Plant (JOI20_power)C++17
100 / 100
217 ms29264 KiB
// #pragma GCC optimize("O3,Ofast,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> using namespace std; #define lli long long int #define MP make_pair #define pb push_back #define REP(i,n) for(int i = 0; (i) < (n); (i)++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const double EPS = 0.00001; const int INF = 1e9+500; const int N = 3e5+5; const int ALPH = 26; const int LGN = 25; constexpr int MOD = 1e9+7; int n,m,q; vector<vector<int> > adj; vector<int> isPow; vector<int> dp; int ans = 0; void dfs(int node, int par) { int sum = 0; for(auto c : adj[node]) { if(c == par) continue; dfs(c, node); sum += dp[c]; } dp[node] = max(isPow[node], sum - isPow[node]); if(isPow[node]) { for(auto c : adj[node]) { ans = max(ans, dp[c] + 1); } } } inline void solve() { cin>>n; adj.assign(n + 1, vector<int>()); isPow.assign(n + 1, 0); dp.assign(n + 1, 0); REP(i, n - 1) { int a,b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } for(int i = 1; i <= n; i++) { char x; cin >> x; if(x == '1') isPow[i] = 1; } dfs(1, 0); ans = max(ans, dp[1]); cout << ans << "\n"; } signed main() { //fastio(); int test = 1; //cin>>test; while(test--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...