Submission #723639

#TimeUsernameProblemLanguageResultExecution timeMemory
723639dxz05Magic Tree (CEOI19_magictree)C++17
47 / 100
1688 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() #define MP make_pair const int N = 100500; vector<int> g[N]; vector<vector<ll>> dp; pair<int, int> fruit[N]; void dfs(int v){ dp[v][fruit[v].first] = fruit[v].second; for (int u : g[v]){ dfs(u); } for (int t = 1; t < dp[v].size(); t++){ for (int u : g[v]){ dp[v][t] += dp[u][t]; } } for (int t = 1; t < dp[v].size(); t++) dp[v][t] = max(dp[v][t], dp[v][t - 1]); } void solve(){ int n, m, k; cin >> n >> m >> k; for (int i = 1; i < n; i++){ int p; cin >> p; --p; g[p].push_back(i); } map<int, int> mp; for (int i = 0; i < m; i++){ int v, d, w; cin >> v >> d >> w; --v; mp[d]; fruit[v] = MP(d, w); } mp[0]; k = 0; for (auto &now : mp){ now.second = ++k; } for (int i = 0; i < n; i++){ fruit[i].first = mp[fruit[i].first]; } dp.assign(n, vector<ll>(k + 1, 0)); dfs(0); cout << dp[0].back() << endl; } int main() { ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); return 0; }

Compilation message (stderr)

magictree.cpp: In function 'void dfs(int)':
magictree.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int t = 1; t < dp[v].size(); t++){
      |                     ~~^~~~~~~~~~~~~~
magictree.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int t = 1; t < dp[v].size(); t++) dp[v][t] = max(dp[v][t], dp[v][t - 1]);
      |                     ~~^~~~~~~~~~~~~~
#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...