이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
out << "[";
for (int i = 0; i < (int)vec.size(); ++i) {
out << vec[i];
if (i + 1 < (int)vec.size())
out << ", ";
}
return out << "]";
}
} // namespace std
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << H;
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbSommet, nbFruits, nbJours;
cin >> nbSommet >> nbFruits >> nbJours;
vector<vector<int>> childs(nbSommet);
for (int i = 1; i < nbSommet; ++i) {
int p;
cin >> p;
childs[p - 1].push_back(i);
}
vector<pair<int, int>> fruits(nbSommet, pair(-1, -1));
for (int i = 0; i < nbFruits; ++i) {
int v, d, w;
cin >> v >> d >> w;
--v;
fruits[v] = pair(d - 1, w);
}
vector<map<int, int>> changements(nbSommet);
for (int u = nbSommet - 1; u >= 0; --u) {
for (int v : childs[u]) {
if (changements[v].size() > changements[u].size())
changements[u].swap(changements[v]);
for (auto [x, delta] : changements[v])
changements[u][x] += delta;
changements[v].clear();
}
if (fruits[u].first == -1)
continue;
auto [d, w] = fruits[u];
int curDel = 0;
int lstDel = -1;
while (true) {
auto it = changements[u].upper_bound(d);
if (it == changements[u].end())
break;
curDel += it->second;
if (curDel <= w) {
changements[u].erase(it);
} else {
changements[u][it->first] = curDel - w;
break;
}
}
changements[u][d] += w;
}
int sol = 0;
for (auto [x, delta] : changements[0])
sol += delta;
cout << sol << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
magictree.cpp: In function 'int main()':
magictree.cpp:64:9: warning: unused variable 'lstDel' [-Wunused-variable]
64 | int lstDel = -1;
| ^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |