| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 83397 | charlies_moo | Dostavljač (COCI18_dostavljac) | C++17 | 206 ms | 804 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
 
using namespace std;
 
typedef vector<int> vi;
typedef struct {
    int *dp1, *dp2;
} node;
 
node dfs(vi e[], int a[], int x, int p, int m) {
    node ret;
    ret.dp1 = new int[m+1];
    ret.dp2 = new int[m+1];
    memset(ret.dp1, 0, sizeof(int) * (m+1));
    memset(ret.dp2, 0, sizeof(int) * (m+1));
    ret.dp1[1] = ret.dp2[1] = a[x];
 
    for (int i = 0; i < e[x].size(); i++) {
        if (e[x][i] == p) {
            continue;
        }
 
        node t = dfs(e, a, e[x][i], x, m);
        for (int j = m; j >= 0; j--) {
            for (int k = 0; k <= j - 1; k++) {
                if (j - k - 2 >= 0) {
                    ret.dp1[j] = max(ret.dp1[j], ret.dp1[j-k-2] + t.dp1[k]);
                    ret.dp2[j] = max(ret.dp2[j], ret.dp2[j-k-2] + t.dp1[k]);
                }
                ret.dp2[j] = max(ret.dp2[j], ret.dp1[j-k-1] + t.dp2[k]);
            }
        }
        
        delete[] t.dp1;
        delete[] t.dp2;
    }
 
    return ret;
}
 
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    vi e[n];
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--, v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
 
    node ret = dfs(e, a, 0, -1, m);
    int ans = 0;
    for (int i = 0; i <= m; i++) {
        ans = max(ans, ret.dp2[i]);
    }
    printf("%d\n", ans);
 
    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... | ||||
| # | 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... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
