답안 #598498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598498 2022-07-18T12:15:03 Z OttoTheDino Chase (CEOI17_chase) C++17
40 / 100
354 ms 524288 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], dpd[mx+1][mxv+1], dpu[mx+1][mxv+1], ans, l;
vi adj[mx+1];
 
void dfs (int u, int par) {

    set<pll,greater<pll>> dpd_nxt[mxv+1], dpu_here[mxv+1];

    rep (i,0,mxv) {
        if (i) {
            dpd[u][i] = s[u]-p[par];
            dpu[u][i] = s[u];
        }
        dpd_nxt[i].insert({0,0});
        dpu_here[i].insert({dpu[u][i], u});
    }

    for (int v : adj[u]) {
        if (v==par) continue;
        dfs (v, u);

        rep (i,0,mxv) {
            dpd_nxt[i].insert({dpd[v][i], v});
            if (len(dpd_nxt[i])>2) dpd_nxt[i].erase(--dpd_nxt[i].end());
            dpd[u][i] = max(dpd[u][i], dpd[v][i]);
            if (i) {
                dpd[u][i] = max(dpd[u][i], s[u]-p[par]+dpd[v][i-1]);
                dpd[u][i] = max(dpd[u][i], dpd[u][i-1]);
            }
        }

        rep (i,0,mxv) {
            dpu_here[i].insert({i==0?dpu[v][i]:max(dpu[v][i], dpu[v][i-1]+s[u]-p[v]), v});
            if (len(dpu_here[i])>2) dpu_here[i].erase(--dpu_here[i].end());
            dpu[u][i] = max(dpu[u][i], dpu[v][i]);
            if (i) {
                dpu[u][i] = max(dpu[u][i], dpu[v][i-1]+s[u]-p[v]);
                dpu[u][i] = max(dpu[u][i], dpu[u][i-1]);
            }
        }
    }

    rep (i,0,l) {
        auto it1 = dpu_here[i].begin();
        auto it2 = dpd_nxt[l-i].begin();
        if ((*it1).se==(*it2).se) {
            ++it2;
            ans = max(ans, (*it1).fi+(*it2).fi);
            --it2;
            ++it1;
        }
        ans = max(ans, (*it1).fi+(*it2).fi);
    }
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    ll n; 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];

    dfs (1,0);

    cout << ans << "\n";
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2732 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2732 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 24 ms 15512 KB Output is correct
8 Correct 23 ms 15444 KB Output is correct
9 Correct 17 ms 4268 KB Output is correct
10 Correct 22 ms 4692 KB Output is correct
11 Correct 22 ms 4624 KB Output is correct
12 Correct 20 ms 4692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 354 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2732 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 24 ms 15512 KB Output is correct
8 Correct 23 ms 15444 KB Output is correct
9 Correct 17 ms 4268 KB Output is correct
10 Correct 22 ms 4692 KB Output is correct
11 Correct 22 ms 4624 KB Output is correct
12 Correct 20 ms 4692 KB Output is correct
13 Runtime error 354 ms 524288 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -