Submission #438657

#TimeUsernameProblemLanguageResultExecution timeMemory
438657soroushPower Plant (JOI20_power)C++17
47 / 100
1564 ms14436 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int , int> pii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 2e5 + 10; const ll mod = 1e9+7; #define pb push_back #define endl '\n' #define dokme(x) cout << x , exit(0) #define ms(x , y) memset(x , y , sizeof x) ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);} int n; string s; vector < int > adj[maxn]; int dfs(int v , int par){ int res = 0; for(int u : adj[v])if(u ^ par) res += dfs(u , v); if(s[v] == '1') res = max(res - 1 , 1); return res; } int solve(int v){ int res = 0; for(auto u : adj[v]) res = max(res , dfs(u , v)); return res + 1; } int32_t main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> n; for(int i = 1 ; i < n ; i ++){ int u , v; cin >> u >> v; u -- , v --; adj[u].pb(v); adj[v].pb(u); } cin >> s; int ans = 0; for(int i = 0 ; i < n ; i ++)if(s[i] == '1') ans = max(ans , solve(i)); cout << ans; return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...