답안 #582552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582552 2022-06-24T05:25:00 Z 반딧불(#8370) Magic Tree (CEOI19_magictree) C++17
0 / 100
2000 ms 20332 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct segTree{
    ll tree[400002];

    void update(int i, int l, int r, int x, ll v){
        if(l==r){
            tree[i] = max(tree[i], v);
            return;
        }
        int m = (l+r)>>1;
        if(x<=m) update(i*2, l, m, x, v);
        else update(i*2+1, m+1, r, x, v);
        tree[i] = max(tree[i*2], tree[i*2+1]);
    }

    ll query(int i, int l, int r, int s, int e){
        if(r<s || e<l) return 0;
        if(s<=l && r<=e) return tree[i];
        int m = (l+r)>>1;
        return max(query(i*2, l, m, s, e), query(i*2+1, m+1, r, s, e));
    }
} tree;

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];

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

    dfs(1);
    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;
    });

    for(int i=1; i<=m; i++){
        Fruit f = arr[i];
        tree.update(1, 1, n, f.v-1, tree.query(1, 1, n, f.v, n) + f.w);
    }
    printf("%lld", tree.query(1, 1, n, 1, n));
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:52:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     for(int i=2; i<=n; i++) scanf("%d", &par[i]), child[par[i]].push_back(i);
      |                             ~~~~~^~~~~~~~~~~~~~~
magictree.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%d %d %d", &v, &d, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 11056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5076 KB Output is correct
2 Correct 4 ms 5076 KB Output is correct
3 Correct 5 ms 5076 KB Output is correct
4 Execution timed out 2094 ms 20332 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 13160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 6100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -