# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
909256 | lighton | Magic Tree (CEOI19_magictree) | C++17 | 2097 ms | 860964 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define forf(i,a,b) for(int i = a; i<=b; i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
int N,M,K;
int inf = 1e9;
struct ST{
int t; ll v; int id;
bool operator<(const ST &r) const{
if(t==r.t) return id<r.id;
return t<r.t;
}
};
set<ST> s[200001];
vector<int> adj[200001];
ST upd[200001];
set<ST> merg (set<ST> a, set<ST> b){
set<ST> ret;
for(ST i : a) ret.insert(i);
for(ST i : b) ret.insert(i);
return ret;
}
void add (set<ST> &now, ST a){
ST tmp = a; tmp.id = inf;
now.insert(a);
auto it = now.upper_bound(tmp);
ll sum = 0; int flag = 0;
ST nxt;
while(it != now.end() && sum <= a.v){
sum += it->v;
if(sum > a.v){
nxt = *it;
flag = 1;
}
it = now.erase(it);
}
if(flag){
nxt.v = sum-a.v;
now.insert(nxt);
}
}
void dfs(int now ,int p = -1){
for(int &i : adj[now]){
if(i==p) continue;
dfs(i,now);
s[now] = merg(s[now],s[i]);
}
if(upd[now].id) add(s[now],upd[now]);
}
int main(){
scanf("%d %d %d" , &N,&M,&K);
forf(i,2,N){
int t; scanf("%d" , &t);
adj[i].push_back(t);
adj[t].push_back(i);
}
forf(i,1,M){
int u,t; ll v; scanf("%d %d %lld" , &u,&t, &v);
upd[u] = {t,v,i};
}
dfs(1);
ll ans = 0;
for(ST i : s[1]) ans += i.v;
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... |