Submission #531697

#TimeUsernameProblemLanguageResultExecution timeMemory
531697Yazan_AlattarMagic Tree (CEOI19_magictree)C++14
47 / 100
2093 ms797812 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define F first #define S second #define pb push_back #define endl "\n" #define all(x) x.begin(), x.end() const int M = 100007; const ll inf = 1e18; const ll mod = 998244353; const double pi = acos(-1); const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0}; const int block = 320; vector <int> adj[M]; int n, m, k, ripe[M], w[M], vert[M]; ll dp[M][1007]; void dfs(int node){ for(auto i : adj[node]){ dfs(i); for(int j = 1; j <= k; ++j) dp[node][j] += dp[i][j]; } dp[node][ripe[node]] += w[node]; for(int i = 1; i <= k; ++i) dp[node][i] = max(dp[node][i], dp[node][i - 1]); return; } int main(){ scanf("%d%d%d", &n, &m, &k); k = min(k, m); for(int i = 2; i <= n; ++i){ int p; scanf("%d", &p); adj[p].pb(i); } vector <int> v; for(int i = 1; i <= m; ++i){ scanf("%d", &vert[i]); scanf("%d%d", &ripe[vert[i]], &w[vert[i]]); v.pb(ripe[vert[i]]); } sort(all(v)); v.erase(unique(all(v)), v.end()); for(int i = 1; i <= m; ++i) for(int j = 0; j < (int)v.size(); ++j) if(v[j] == ripe[vert[i]]){ripe[vert[i]] = j + 1; break;} dfs(1); printf("%lld\n", dp[1][k]); return 0; }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d%d", &n, &m, &k); k = min(k, m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:35:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   int p; scanf("%d", &p);
      |          ~~~~~^~~~~~~~~~
magictree.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d", &vert[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~
magictree.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d%d", &ripe[vert[i]], &w[vert[i]]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...