이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,i,day[100005],x[100005],node,d,w,p[100005],ans;
vector<ll> v[100005];
map<ll,ll> mp[100005];
map<ll,ll> ::iterator it;
void dfs(ll a){
for(ll i:v[a]){
dfs(i);
if(mp[a].size()<mp[i].size()) swap(mp[a],mp[i]);
for(it=mp[i].begin();it!=mp[i].end();it++){
mp[a][it->first]+=it->second;
}
}
if(day[a]>0){
mp[a][day[a]]+=x[a];
while(true){
it=mp[a].upper_bound(day[a]);
if(it==mp[a].end()) break;
if(it->second<=x[a]){
x[a]-=it->second;
mp[a].erase(it);
continue;
}
it->second-=x[a];
break;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for(i=2;i<=n;i++){
cin >> p[i];
v[p[i]].push_back(i);
}
for(i=1;i<=m;i++){
cin >> node >> d >> w;
day[node]=d;
x[node]=w;
}
dfs(1);
for(it=mp[1].begin();it!=mp[1].end();it++) ans+=it->second;
cout << ans;
}
# | 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... |