Submission #101429

# Submission time Handle Problem Language Result Execution time Memory
101429 2019-03-19T01:47:52 Z shenxy Chase (CEOI17_chase) C++11
20 / 100
851 ms 525312 KB
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int n, v;
vector<long long int> p;
vector< vector<int> > adjlist;
vector< vector<int> > children;
vector< vector< vector<long long int> > > dptable;
long long int smalldp(int v, int pa, int crumbs) {
    if (dptable[v][pa][crumbs] != -1) return dptable[v][pa][crumbs];
    if (crumbs == 0) return 0;
    long long int ans = 0, maxdp = 0, maxnocrumb = 0;
    for (int i = 0; i < adjlist[v].size(); i++) {
        if (adjlist[v][i] == pa) continue;
        ans += p[adjlist[v][i]];
        maxdp = max(maxdp, smalldp(adjlist[v][i], v, crumbs - 1));
        maxnocrumb = max(maxnocrumb, smalldp(adjlist[v][i], v, crumbs));
    }
    return dptable[v][pa][crumbs] = max(maxdp + ans, maxnocrumb);
}
int main() {
    scanf("%d %d", &n, &v);
    long long int nextint;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &nextint);
        p.push_back(nextint);
        adjlist.push_back(vector<int>());
    }
    int a, b;
    for (int i = 1; i < n; i++) {
        scanf("%d %d", &a, &b);
        adjlist[a - 1].push_back(b - 1);
        adjlist[b - 1].push_back(a - 1);
    }
    if (n <= 1000) {
        for (int i = 0; i < n; i++) {
            dptable.push_back(vector< vector<long long int> >(n + 1, vector<long long int>(v + 1, -1)));
        }
        long long int ans = 0;
        for (int i = 0; i < n; i++) {
            ans = max(ans, smalldp(i, n, v));
        }
        printf("%lld\n", ans);
        return 0;
    } else {
        for (int i = 0; i < n; i++) {
            dptable.push_back(vector< vector<long long int> >(v, {-1}));
            children.push_back(vector<int>());
        }
    }
}

Compilation message

chase.cpp: In function 'long long int smalldp(int, int, int)':
chase.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < adjlist[v].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
chase.cpp: In function 'int main()':
chase.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &v);
     ~~~~~^~~~~~~~~~~~~~~~~
chase.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &nextint);
         ~~~~~^~~~~~~~~~~~~~~~~~
chase.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Runtime error 729 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 851 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Runtime error 729 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -