Submission #211240

# Submission time Handle Problem Language Result Execution time Memory
211240 2020-03-19T16:26:44 Z Lawliet Magic Tree (CEOI19_magictree) C++14
34 / 100
2000 ms 36856 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;

const int MAXK = 30;
const int MAXN = 100010;

int n, m, k;

int t[MAXN];
int w[MAXN];

lli dp[MAXN][MAXK];

vector< int > adj[MAXN];

void DFS(int cur)
{
	for(int i = 0 ; i < adj[cur].size() ; i++)
		DFS( adj[cur][i] );

	for(int j = 1 ; j <= k ; j++)
	{
		lli sum = 0;
		if( t[cur] == j ) sum = w[cur];

		for(int i = 0 ; i < adj[cur].size() ; i++)
			sum += dp[ adj[cur][i] ][j];

		dp[cur][j] = max( dp[cur][j - 1] , sum );
	}
}

int main()
{
	scanf("%d %d %d",&n,&m,&k);

	for(int i = 2 ; i <= n ; i++)
	{
		int p;
		scanf("%d",&p);

		adj[p].push_back( i );
	}

	for(int i = 1 ; i <= m ; i++)
	{
		int node;
		scanf("%d",&node);
		scanf("%d %d",&t[node],&w[node]);
	}

	DFS( 1 );

	printf("%lld\n",dp[1][k]);
}

Compilation message

magictree.cpp: In function 'void DFS(int)':
magictree.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < adj[cur].size() ; i++)
                  ~~^~~~~~~~~~~~~~~~~
magictree.cpp:28:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < adj[cur].size() ; i++)
                   ~~^~~~~~~~~~~~~~~~~
magictree.cpp: In function 'int main()':
magictree.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
magictree.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&p);
   ~~~~~^~~~~~~~~
magictree.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&node);
   ~~~~~^~~~~~~~~~~~
magictree.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&t[node],&w[node]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 6 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2091 ms 28408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3072 KB Output is correct
2 Correct 16 ms 3072 KB Output is correct
3 Correct 10 ms 3072 KB Output is correct
4 Execution timed out 2084 ms 12748 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 28536 KB Output is correct
2 Correct 93 ms 30712 KB Output is correct
3 Correct 106 ms 33560 KB Output is correct
4 Correct 75 ms 29268 KB Output is correct
5 Correct 81 ms 36856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 6 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
10 Correct 107 ms 28536 KB Output is correct
11 Correct 104 ms 28532 KB Output is correct
12 Correct 106 ms 31352 KB Output is correct
13 Correct 75 ms 27500 KB Output is correct
14 Correct 78 ms 34680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2087 ms 8320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 6 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
10 Correct 10 ms 3072 KB Output is correct
11 Correct 16 ms 3072 KB Output is correct
12 Correct 10 ms 3072 KB Output is correct
13 Execution timed out 2084 ms 12748 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 6 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 6 ms 2688 KB Output is correct
10 Execution timed out 2091 ms 28408 KB Time limit exceeded
11 Halted 0 ms 0 KB -