# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
932479 | andrei_boaca | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 198 ms | 206684 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e17;
map<ll,ll> nrm;
ll nr;
vector<ll> muchii[200005];
ll n,par[200005],v[200005],cost[200005];
ll dp[5005][5005];
void dfs(ll nod)
{
for(ll i:muchii[nod])
{
dfs(i);
ll minim=INF;
for(int j=nr;j>=1;j--)
{
minim=min(minim,dp[i][j]);
dp[nod][j]+=minim;
}
}
for(int i=1;i<=nr;i++)
if(i!=v[nod])
dp[nod][i]+=cost[nod];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
vector<ll> vals;
for(int i=1;i<=n;i++)
{
cin>>par[i]>>v[i]>>cost[i];
if(i!=1)
muchii[par[i]].push_back(i);
vals.push_back(v[i]);
}
sort(vals.begin(),vals.end());
vals.erase(unique(vals.begin(),vals.end()),vals.end());
for(int i=0;i<vals.size();i++)
nrm[vals[i]]=i+1;
nr=vals.size();
for(int i=1;i<=n;i++)
v[i]=nrm[v[i]];
dfs(1);
ll ans=INF;
for(ll i=1;i<=nr;i++)
ans=min(ans,dp[1][i]);
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (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... |