Submission #211240

#TimeUsernameProblemLanguageResultExecution timeMemory
211240LawlietMagic Tree (CEOI19_magictree)C++14
34 / 100
2091 ms36856 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...