Submission #598150

# Submission time Handle Problem Language Result Execution time Memory
598150 2022-07-17T17:48:57 Z OttoTheDino Chase (CEOI17_chase) C++17
30 / 100
571 ms 174288 KB
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,s,e)                  for (ll i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (ll i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
#define len(a)                      (ll)a.size()
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
 
const ll mx = 1e5, mxv = 100;
ll p[mx+1], s[mx+1];
vi adj[mx+1];
ll dp2[mx+1][mxv+1], done[mx+1][mxv+1];
 
ll dfs2 (int u, int par, int cnt) {
    if (cnt==0) return 0;
 
    if (done[u][cnt]) return dp2[u][cnt];
 
    dp2[u][cnt] = s[u]-p[par];
 
    for (int v : adj[u]) {
        if (v==par) continue;
        dp2[u][cnt] = max(dp2[u][cnt], max(s[u]-p[par]+dfs2(v,u,cnt-1), dfs2(v,u,cnt))); 
    }
 
    done[u][cnt] = 1;
    return dp2[u][cnt];
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    ll n, l; cin >> n >> l;
 
    rep (i,1,n) cin >> p[i];
 
    rep (i,1,n-1) {
        ll u, v; cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
 
    rep (i,1,n) for (int v : adj[i]) s[i] += p[v];
 
    cout << dfs2 (1, 0, l) << "\n";
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 384 ms 174288 KB Output is correct
2 Correct 391 ms 174248 KB Output is correct
3 Correct 109 ms 168284 KB Output is correct
4 Correct 131 ms 168140 KB Output is correct
5 Correct 571 ms 168280 KB Output is correct
6 Correct 472 ms 168168 KB Output is correct
7 Correct 549 ms 168232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -