답안 #582545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582545 2022-06-24T05:06:32 Z 조영욱(#8372) Magic Tree (CEOI19_magictree) C++17
0 / 100
66 ms 42972 KB
#include <bits/stdc++.h>
using namespace std;

int n,m,k;
long long dp[100001][21];
vector<int> son[100001];
int t[100001];
int val[100001];

long long ans(int v,int d){
    if (dp[v][d]!=-1) {
        return dp[v][d];
    }
    long long ret=0;
    if (t[v]==d) {
        ret+=val[v];
    }
    for(int i=0;i<son[v].size();i++){
        long long temp=ans(son[v][i],d);
        if (t[son[v][i]]!=0) {
            temp=max(temp,ans(son[v][i],t[son[v][i]]));
        }
    ret+=temp;
    }
    return dp[v][d]=ret;
}

int main() {
    scanf("%d %d %d",&n,&m,&k);
    for(int i=2;i<=n;i++) {
        int p;
        scanf("%d",&p);
        son[p].push_back(i);
    }
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<m;i++) {
        int v,d,w;
        scanf("%d %d %d",&v,&d,&w);
        t[v]=d;
        val[v]=w;
    }
    printf("%lld",ans(1,k));
    return 0;
}

Compilation message

magictree.cpp: In function 'long long int ans(int, int)':
magictree.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<son[v].size();i++){
      |                 ~^~~~~~~~~~~~~~
magictree.cpp: In function 'int main()':
magictree.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d %d %d",&n,&m,&k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
magictree.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d",&p);
      |         ~~~~~^~~~~~~~~
magictree.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d %d %d",&v,&d,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 50 ms 42972 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 21468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 19540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -