# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1093142 | 12345678 | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 294 ms | 119344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
#define ll long long
ll n, pa[nx], h[nx], c[nx];
vector<ll> d[nx];
map<ll, ll> mp[nx];
void dfs(int u)
{
mp[u][0]=c[u];
for (auto v:d[u])
{
dfs(v);
if (mp[v].size()>mp[u].size()) swap(mp[u], mp[v]);
for (auto [x, y]:mp[v]) mp[u][x]+=y;
}
mp[u][h[u]]+=0;
mp[u][h[u]+1]+=c[u];
auto itr=mp[u].find(h[u]);
ll sm=-c[u], lst=h[u];
while (1)
{
sm+=itr->second;
if (sm>=0) break;
itr=mp[u].erase(itr);
itr--;
}
mp[u][itr->first]=sm;
//cout<<"debug "<<u<<'\n';
//cout<<"mp ";
//for (auto x:mp[u]) cout<<x.first<<' '<<x.second<<'\n';
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>pa[i]>>h[i]>>c[i];
for (int i=2; i<=n; i++) d[pa[i]].push_back(i);
dfs(1);
cout<<mp[1].begin()->second;
}
컴파일 시 표준 에러 (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... |