# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
392103 |
2021-04-20T13:58:56 Z |
sinamhdv |
Chase (CEOI17_chase) |
C++11 |
|
348 ms |
230684 KB |
// CEOI17_chase
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 100100
#define MAXB 110
int n, B;
int p[MAXN];
ll a[MAXN];
vector<int> adj[MAXN];
ll ans = 0;
ll up[MAXN][MAXB];
ll dn[MAXN][MAXB];
void dfs(int v, int par)
{
FOR(k, 1, B + 1)
up[v][k] = a[v];
for (int u : adj[v])
{
if (u == par) continue;
dfs(u, v);
ll udp[MAXB] = {}, ddp[MAXB] = {};
FOR(k, 1, B + 1)
{
udp[k] = max(up[u][k], up[u][k - 1] + a[v] - p[u]);
ddp[k] = max(dn[u][k], dn[u][k - 1] + a[u] - p[v]);
}
FOR(k, 0, B + 1)
ans = max({ans, dn[v][k] + udp[B - k], up[v][k] + ddp[B - k]});
FOR(k, 1, B + 1)
{
up[v][k] = max(up[v][k], udp[k]);
dn[v][k] = max(dn[v][k], ddp[k]);
}
}
}
int32_t main(void)
{
fast_io;
cin >> n >> B;
FOR(i, 1, n + 1) cin >> p[i];
FOR(i, 1, n)
{
int x, y;
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
a[x] += p[y];
a[y] += p[x];
}
if (B == 0) return cout << "0\n", 0;
dfs(1, -1);
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
3532 KB |
Output is correct |
10 |
Correct |
5 ms |
4300 KB |
Output is correct |
11 |
Correct |
4 ms |
4300 KB |
Output is correct |
12 |
Correct |
4 ms |
4300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
229900 KB |
Output is correct |
2 |
Correct |
296 ms |
229444 KB |
Output is correct |
3 |
Correct |
172 ms |
95736 KB |
Output is correct |
4 |
Correct |
185 ms |
165952 KB |
Output is correct |
5 |
Correct |
348 ms |
168572 KB |
Output is correct |
6 |
Correct |
292 ms |
168324 KB |
Output is correct |
7 |
Correct |
291 ms |
168152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
3532 KB |
Output is correct |
10 |
Correct |
5 ms |
4300 KB |
Output is correct |
11 |
Correct |
4 ms |
4300 KB |
Output is correct |
12 |
Correct |
4 ms |
4300 KB |
Output is correct |
13 |
Correct |
292 ms |
229900 KB |
Output is correct |
14 |
Correct |
296 ms |
229444 KB |
Output is correct |
15 |
Correct |
172 ms |
95736 KB |
Output is correct |
16 |
Correct |
185 ms |
165952 KB |
Output is correct |
17 |
Correct |
348 ms |
168572 KB |
Output is correct |
18 |
Correct |
292 ms |
168324 KB |
Output is correct |
19 |
Correct |
291 ms |
168152 KB |
Output is correct |
20 |
Correct |
289 ms |
168220 KB |
Output is correct |
21 |
Correct |
50 ms |
9132 KB |
Output is correct |
22 |
Correct |
283 ms |
168132 KB |
Output is correct |
23 |
Correct |
188 ms |
166080 KB |
Output is correct |
24 |
Correct |
291 ms |
168324 KB |
Output is correct |
25 |
Correct |
160 ms |
95276 KB |
Output is correct |
26 |
Correct |
296 ms |
230684 KB |
Output is correct |
27 |
Correct |
289 ms |
230620 KB |
Output is correct |