답안 #582549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582549 2022-06-24T05:15:09 Z 반딧불(#8370) Magic Tree (CEOI19_magictree) C++17
0 / 100
71 ms 22440 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=-1;
vector<pair<int, ll> > fruit[100002];
int state[100002];
Fruit arr[100002];

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);
}

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<=m; i++){
        Fruit f = arr[i];
        for(int b=(1<<n)-1; b>=0; b--){
            if(b & (1<<in[f.v])) 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:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:32:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     for(int i=2; i<=n; i++) scanf("%d", &par[i]), child[par[i]].push_back(i);
      |                             ~~~~~^~~~~~~~~~~~~~~
magictree.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d %d %d", &v, &d, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 51 ms 13128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 18296 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 10152 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 71 ms 22440 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 51 ms 13128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 11340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 51 ms 13128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 51 ms 13128 KB Output isn't correct
3 Halted 0 ms 0 KB -