Submission #896404

#TimeUsernameProblemLanguageResultExecution timeMemory
896404math_rabbit_1028Magic Tree (CEOI19_magictree)C++14
37 / 100
2067 ms837420 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int n, m, k, par[101010]; pii arr[101010]; vector<int> adj[101010]; map<int, ll> dp[101010]; ll solve(int v, int d) { if (dp[v].find(d) != dp[v].end()) return dp[v][d]; ll a = 0, b = arr[v].second; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; a += solve(u, d); if (arr[v].first >= 1 && arr[v].first <= d) b += solve(u, arr[v].first); } if (arr[v].first >= 1 && arr[v].first <= d) return dp[v][d] = max(a, b); else return dp[v][d] = a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 2; i <= n; i++) { cin >> par[i]; adj[par[i]].push_back(i); } for (int i = 1; i <= m; i++) { int v, d, w; cin >> v >> d >> w; arr[v] = {d, w}; } cout << solve(1, k) << "\n"; return 0; }

Compilation message (stderr)

magictree.cpp: In function 'll solve(int, int)':
magictree.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < adj[v].size(); 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...