제출 #1051467

#제출 시각아이디문제언어결과실행 시간메모리
1051467otariusMagic Tree (CEOI19_magictree)C++17
100 / 100
242 ms34508 KiB
#include <bits/stdc++.h> #include <bits/extc++.h> using namespace __gnu_pbds; using namespace std; // #pragma GCC optimize("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ff first #define sc second #define pb push_back #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define ull unsigned long long #define all(x) (x).begin(),(x).end() // #define int long long // #define int unsigned long long // #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> // #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update> void open_file(string filename) { freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } // const ll mod = 1e9 + 7; // const ll mod = 998244353; const ll inf = 1e9; const ll biginf = 1e18; const int maxN = 1e5 + 25; vector<int> g[maxN]; map<int, ll> dp[maxN]; int n, m, k, d[maxN], w[maxN]; void dfs(int v, int par) { for (int u : g[v]) { if (u == par) continue; dfs(u, v); if (dp[v].size() < dp[u].size()) swap(dp[v], dp[u]); for (auto x : dp[u]) dp[v][x.ff] += x.sc; dp[u].clear(); } auto it = dp[v].upper_bound(d[v]); ll cnt = w[v]; for ( ; it != dp[v].end(); ++it) { if (it -> sc < cnt) { cnt -= it -> sc; it -> sc = 0; } else { it -> sc -= cnt; break; } } dp[v][d[v]] += w[v]; } void solve() { cin >> n >> m >> k; for (int i = 2; i <= n; i++) { int x; cin >> x; g[x].pb(i); } for (int i = 1; i <= m; i++) { int _v, _d, _w; cin >> _v >> _d >> _w; d[_v] = _d; w[_v] = _w; } dfs(1, -1); ll ans = 0; for (auto x : dp[1]) ans += x.sc; cout << ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

magictree.cpp: In function 'void open_file(std::string)':
magictree.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".out").c_str(), "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...