Submission #561230

#TimeUsernameProblemLanguageResultExecution timeMemory
561230fatemetmhrChase (CEOI17_chase)C++17
0 / 100
41 ms9844 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define pb push_back #define all(x) x.begin(), x.end() #define fi first #define se second #define mp make_pair const int maxn5 = 1e5 + 10; const int ssq = 320; const ll inf = 1e18; ll h[maxn5], have[maxn5]; ll a[maxn5], lim, ans = 0; vector <int> adj[maxn5]; inline void dfs(int v, int par){ for(auto u : adj[v]) if(u != par) have[v] += a[u]; have[v] += a[v]; if(h[v] < lim) ans = max(ans, have[v]); for(auto u : adj[v]) if(u != par){ h[u] = h[v] + 1; have[u] = have[v] - a[u]; dfs(u, v); } //cout << v << ' ' << h[v] << ' ' << have[v] << endl; return; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n >> lim; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n - 1; i++){ int a, b; cin >> a >> b; a--; b--; adj[a].pb(b); adj[b].pb(a); } dfs(0, -1); cout << ans - a[0] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...