Submission #1095755

# Submission time Handle Problem Language Result Execution time Memory
1095755 2024-10-03T06:41:19 Z alexander707070 Magic Tree (CEOI19_magictree) C++14
34 / 100
85 ms 40764 KB
#include<bits/stdc++.h>
#define MAXN 100007
using namespace std;

int n,m,k,p[MAXN],a,d,w;
pair<int,int> cost[MAXN];
vector<int> v[MAXN];

long long dp[MAXN][27];
bool vis[MAXN][27];

long long ff(int x,int day){
	if(vis[x][day])return dp[x][day];
	vis[x][day]=true;

	if(day==cost[x].first)dp[x][day]+=cost[x].second;

	for(int i=0;i<v[x].size();i++){
		dp[x][day]+=ff(v[x][i],day);
	}

	if(day>1)dp[x][day]=max(dp[x][day],ff(x,day-1));

	return dp[x][day];
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin>>n>>m>>k;
	for(int i=2;i<=n;i++){
		cin>>p[i];
		v[p[i]].push_back(i);
	}

	for(int i=1;i<=m;i++){
		cin>>a>>d>>w;
		cost[a]={d,w};
	}

	cout<<ff(1,20)<<"\n";

    return 0;
}

Compilation message

magictree.cpp: In function 'long long int ff(int, int)':
magictree.cpp:18:15: 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<v[x].size();i++){
      |              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2820 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2812 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 30044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Incorrect 1 ms 3080 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 31352 KB Output is correct
2 Correct 85 ms 31312 KB Output is correct
3 Correct 65 ms 35408 KB Output is correct
4 Correct 55 ms 29904 KB Output is correct
5 Correct 52 ms 40764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2820 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2812 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2828 KB Output is correct
10 Correct 81 ms 30800 KB Output is correct
11 Correct 72 ms 30724 KB Output is correct
12 Correct 63 ms 34640 KB Output is correct
13 Correct 51 ms 29140 KB Output is correct
14 Correct 54 ms 40020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 8024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2820 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2812 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2828 KB Output is correct
10 Correct 2 ms 3160 KB Output is correct
11 Incorrect 1 ms 3080 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2820 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2812 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2828 KB Output is correct
10 Incorrect 65 ms 30044 KB Output isn't correct
11 Halted 0 ms 0 KB -