# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
242391 | tqbfjotld | Magic Tree (CEOI19_magictree) | C++14 | 191 ms | 29048 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool fruit[100005];
int day[100005];
int val[100005];
vector<int> adjl[100005];
int n,m,k;
map<int,int> func(int node){
map<int,int> ans;
if (adjl[node].size()>=1){
ans = func(adjl[node][0]);
}
for (int x = 1; x<adjl[node].size(); x++){
int ch = adjl[node][x];
auto res = func(ch);
if (res.size()>ans.size()){
swap(res,ans);
}
for (auto item : res){
ans[item.first] += item.second;
}
}
if (fruit[node]){
ans[day[node]] += val[node];
int t = val[node];
auto it = ans.upper_bound(day[node]);
while (t>0&& it!=ans.end()){
if ((*it).second<=t){
t -= (*it).second;
it = ans.erase(it);
}
else{
ans[(*it).first] -= t;
break;
}
}
}
return ans;
}
main(){
scanf("%lld%lld%lld",&n,&m,&k);
for (int x = 1; x<n; x++){
int t;
scanf("%lld",&t);
t--;
adjl[t].push_back(x);
}
for (int x = 0; x<m; x++){
int a,b;
long long c;
scanf("%lld%lld%lld",&a,&b,&c);
a--;
fruit[a] = true;
day[a] = b;
val[a] = c;
}
auto res = func(0);
long long ans = 0;
for (auto x : res){
ans += x.second;
}
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |