이 제출은 이전 버전의 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;
void dfs(ll a){
map<ll,ll> mp2;
for(ll i:v[a]){
dfs(i);
if(mp2.size()<mp.size()) swap(mp2,mp);
for(auto [p,q]:mp){
mp2[p]+=q;
}
}
if(day[a]>0){
mp2[day[a]]+=x[a];
while(true){
auto it=mp2.upper_bound(day[a]);
if(it==mp2.end()) break;
if(it->second<=x[a]){
x[a]-=it->second;
mp2.erase(it);
continue;
}
it->second-=x[a];
break;
}
}
swap(mp2,mp);
}
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(auto [a,b]:mp) ans+=b;
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:12:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
12 | for(auto [p,q]:mp){
| ^
magictree.cpp: In function 'int main()':
magictree.cpp:47:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [a,b]:mp) ans+=b;
| ^
# | 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... |