제출 #1149929

#제출 시각아이디문제언어결과실행 시간메모리
1149929dostsPower Plant (JOI20_power)C++20
0 / 100
4 ms9800 KiB
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3,unroll-loops") using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define all(cont) cont.begin(),cont.end() #define vi vector<int> const int inf = 1e17,N = 3e5+1,MOD = 1e9+7,BL = 1000; vi edges[N],dp(N); string c; int dfs(int node,int p) { int sm = 0; for (auto it : edges[node]) { if (it == p) continue; int d = dfs(it,node); dp[node] = max(dp[node],dp[it]); sm += d; } dp[node] = max(0ll,sm-(c[node-1] == '1')); if (c[node-1] == '1' && node != p) dp[node] = max(dp[node],1ll); return dp[node]; } void solve() { int n; cin >> n; for (int i=1;i<n;i++) { int a,b; cin >> a >> b; edges[a].push_back(b); edges[b].push_back(a); } cin >> c; if (n <= 2) { cout << count(all(c),'1') << '\n'; return; } int ans = 0; for (int i=1;i<=n;i++) { dfs(i,i); ans = max(ans,dp[i]); } cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Dodi freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while (t --> 0) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...