# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
561230 |
2022-05-12T13:41:52 Z |
fatemetmhr |
Chase (CEOI17_chase) |
C++17 |
|
41 ms |
9844 KB |
#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 time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
9844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |