Submission #242367

#TimeUsernameProblemLanguageResultExecution timeMemory
242367dantoh000Magic Tree (CEOI19_magictree)C++14
48 / 100
115 ms37984 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n,m,k; int p[100005]; vector<int> G[100005]; int a[100005]; int L[100005]; int V[100005][20]; ll dp[100005][20]; bool isline = 1; ll LEAFANS = 0; void dfs(int u){ dp[u][0] = dp[u][1] = 0; for (auto v: G[u]){ dfs(v); for (int i = 0; i < k; i++) dp[u][i] += dp[v][i]; } for (int i = 0; i < k; i++){ dp[u][i] += V[u][i]; } for (int i = k-2; i >= 0; i--){ dp[u][i] = max(dp[u][i],dp[u][i+1]); } } int main(){ scanf("%d%d%d",&n,&m,&k); for (int i = 2; i <= n; i++){ scanf("%d",&p[i]); G[p[i]].push_back(i); if (p[i] != i-1) isline = false; } for (int i = 0; i < m; i++){ int v,d,w; scanf("%d%d%d",&v,&d,&w); a[v] = d; LEAFANS += w; if (k <= 20) V[v][k-d] += w; } if (k <= 20){ dfs(1); printf("%lld\n",dp[1][0]); } else if (isline){ int ans = 0; for (int i = 0; i <= n; i++) L[i] = 1000000005; for (int i = n; i >= 1; i--){ if (a[i] == 0) continue; int pos = upper_bound(L,L+ans,a[i])-L; //printf("%d goes %d\n",a[i],pos); L[pos] = a[i]; ans = max(ans,pos+1); } printf("%d\n",ans); } else printf("%lld\n",LEAFANS); }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:27:10: 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:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&p[i]);
         ~~~~~^~~~~~~~~~~~
magictree.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&v,&d,&w);
         ~~~~~^~~~~~~~~~~~~~~~~~~
#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...