Submission #1086273

#TimeUsernameProblemLanguageResultExecution timeMemory
1086273vjudge1Magic Tree (CEOI19_magictree)C++14
34 / 100
54 ms32348 KiB
#include<bits/stdc++.h> using namespace std; #define NAME "" #define ll long long #define pii pair < int , int > #define fi first #define se second #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i ++) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i --) #define REP(i, n) for (int i = 0, _n = (n); i < _n; i ++) #define bit(x, i) (((x) >> (i)) & 1ll) #define mask(x) (1ll << (x)) #define mem(f, x) memset(f, x, sizeof(f)) #define sz(x) (int32_t) (x.size()) const int nmax = 1e5; int lim; pii fruit[nmax + 5]; vector < int > adj[nmax + 5]; vector < vector < ll > > dp; void dfs(int i) { for (auto x: adj[i]) { dfs(x); ll cur = 0; FOR(j, 0, lim) { cur = max(cur, dp[x][j]); dp[i][j] += cur; } } dp[i][fruit[i].fi] += fruit[i].se; // cout << i << ":\n"; // FOR(j, 1, lim) { // cout << j << " " << dp[i][j] << "\n"; // } } signed main() { if (fopen(NAME".inp", "r")) { freopen(NAME".inp", "r", stdin); freopen(NAME".ans", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m >> lim; if (n * lim > (int)1e7) { return 0; } dp.assign(n + 1, vector < ll > (lim + 1, 0)); FOR(i, 2, n) { int p; cin >> p; adj[p].push_back(i); } for (; m --;) { int v, d, w; cin >> v >> d >> w; fruit[v] = {d, w}; } dfs(1); ll ans = 0; FORD(j, lim, 0) { ans = max(ans, dp[1][j]); } cout << ans; return 0; }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen(NAME".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     freopen(NAME".ans", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...