| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 48498 | WLZ | Paprike (COI18_paprike) | C++17 | 93 ms | 29632 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
typedef long long ll;
const int INF = 1e9;
const int MAXN = 1e5 + 5;
const ll LINF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-9;
template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>;
template <class T> using MaxPQ = priority_queue<T>;
 
int n;
ll k;
int ops;
vector<ll> a;
vector< vector<int> > g;
bitset<MAXN> used;
vector<int> p;
vector<int> v;
vector<int> h;
 
ll preCalc(int u, int par) {
    p[u] = par;
    vector <ll> children;
    ll ans = a[u];
    for (int& x : g[u]) {
        if (x != par) {
            children.push_back(preCalc(x, u));
            ans += children.back();
        }
    }
    sort(children.begin(),children.end());
    int pos = (int)(children.size() - 1);
    while (ans > k) {
        ans -= children[pos];
        ops ++;
        pos --;
    }
    return ans;
}
 
int main() {
    #ifdef DEBUG
    //freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    scanf("%d %lld", &n, &k);
    p.assign(n, -1);
    g.assign(n, vector<int>());
    a.assign(n, 0);
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d %d", &x, &y); --x; --y;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    ops = 0;
    preCalc(0, -1);
    printf("%d\n", ops);
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
