Submission #582547

# Submission time Handle Problem Language Result Execution time Memory
582547 2022-06-24T05:08:05 Z 반딧불(#8370) Magic Tree (CEOI19_magictree) C++17
0 / 100
75 ms 22380 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Fruit{
    int v, d; ll w;
    Fruit(){}
    Fruit(int v, int d, ll w): v(v), d(d), w(w){}
};

int n, m, k;
int par[100002];
vector<int> child[100002];
int in[100002], out[100002], inCnt;
vector<pair<int, ll> > fruit[100002];
int state[100002];
Fruit arr[100002];

int stateSum[1048576];
ll DP[1048576];

void dfs(int x){
    in[x] = ++inCnt;
    for(auto y: child[x]) dfs(y);
    out[x] = inCnt;
    for(int i=in[x]; i<=out[x]; i++) state[x] |= (1<<(i-1));
}

int main(){
    scanf("%d %d %d", &n, &m, &k);
    for(int i=2; i<=n; i++) scanf("%d", &par[i]), child[par[i]].push_back(i);
    ll ans = 0;
    for(int i=1; i<=m; i++){
        int v, d, w;
        scanf("%d %d %d", &v, &d, &w);
        fruit[d].push_back(make_pair(v, w));
        arr[i] = Fruit(v, d, w);
        ans += w;
    }
    sort(arr+1, arr+m+1, [&](Fruit &a, Fruit &b){
        if(a.d==b.d) return in[a.v]>in[b.v];
        return a.d<b.d;
    });

    dfs(1);
    for(int i=1; i<(1<<n); i++){
        int x = __builtin_ctz(i);
        stateSum[i] = stateSum[i-(1<<x)] | state[x+1];
    }
    for(int i=1; i<=m; i++){
        Fruit f = arr[i];
        for(int b=(1<<n)-1; b>=0; b--){
            if(b & (1<<(f.v-1))) continue;
            DP[b|state[f.v]] = max(DP[b|state[f.v]], DP[b]+f.w);
        }
    }
    printf("%lld", *max_element(DP, DP+(1<<n)));
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:33:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     for(int i=2; i<=n; i++) scanf("%d", &par[i]), child[par[i]].push_back(i);
      |                             ~~~~~^~~~~~~~~~~~~~~
magictree.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d %d %d", &v, &d, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 18216 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 10140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 75 ms 22380 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 11308 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -