#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;
}
Compilation message
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i=0;i<vals.size();i++)
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
90 ms |
206376 KB |
Output is correct |
6 |
Correct |
29 ms |
205904 KB |
Output is correct |
7 |
Correct |
27 ms |
206176 KB |
Output is correct |
8 |
Correct |
75 ms |
206664 KB |
Output is correct |
9 |
Correct |
27 ms |
205920 KB |
Output is correct |
10 |
Correct |
33 ms |
205916 KB |
Output is correct |
11 |
Correct |
16 ms |
105048 KB |
Output is correct |
12 |
Correct |
64 ms |
206684 KB |
Output is correct |
13 |
Correct |
26 ms |
206172 KB |
Output is correct |
14 |
Correct |
67 ms |
206504 KB |
Output is correct |
15 |
Correct |
27 ms |
206164 KB |
Output is correct |
16 |
Correct |
66 ms |
206420 KB |
Output is correct |
17 |
Correct |
30 ms |
205976 KB |
Output is correct |
18 |
Correct |
14 ms |
109660 KB |
Output is correct |
19 |
Correct |
69 ms |
206388 KB |
Output is correct |
20 |
Correct |
28 ms |
206172 KB |
Output is correct |
21 |
Correct |
25 ms |
206188 KB |
Output is correct |
22 |
Correct |
66 ms |
206264 KB |
Output is correct |
23 |
Correct |
26 ms |
205908 KB |
Output is correct |
24 |
Correct |
65 ms |
206380 KB |
Output is correct |
25 |
Correct |
28 ms |
206148 KB |
Output is correct |
26 |
Correct |
64 ms |
206672 KB |
Output is correct |
27 |
Correct |
70 ms |
206420 KB |
Output is correct |
28 |
Correct |
68 ms |
206624 KB |
Output is correct |
29 |
Correct |
66 ms |
206672 KB |
Output is correct |
30 |
Correct |
64 ms |
206420 KB |
Output is correct |
31 |
Correct |
64 ms |
206416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
90 ms |
206376 KB |
Output is correct |
6 |
Correct |
29 ms |
205904 KB |
Output is correct |
7 |
Correct |
27 ms |
206176 KB |
Output is correct |
8 |
Correct |
75 ms |
206664 KB |
Output is correct |
9 |
Correct |
27 ms |
205920 KB |
Output is correct |
10 |
Correct |
33 ms |
205916 KB |
Output is correct |
11 |
Correct |
16 ms |
105048 KB |
Output is correct |
12 |
Correct |
64 ms |
206684 KB |
Output is correct |
13 |
Correct |
26 ms |
206172 KB |
Output is correct |
14 |
Correct |
67 ms |
206504 KB |
Output is correct |
15 |
Correct |
27 ms |
206164 KB |
Output is correct |
16 |
Correct |
66 ms |
206420 KB |
Output is correct |
17 |
Correct |
30 ms |
205976 KB |
Output is correct |
18 |
Correct |
14 ms |
109660 KB |
Output is correct |
19 |
Correct |
69 ms |
206388 KB |
Output is correct |
20 |
Correct |
28 ms |
206172 KB |
Output is correct |
21 |
Correct |
25 ms |
206188 KB |
Output is correct |
22 |
Correct |
66 ms |
206264 KB |
Output is correct |
23 |
Correct |
26 ms |
205908 KB |
Output is correct |
24 |
Correct |
65 ms |
206380 KB |
Output is correct |
25 |
Correct |
28 ms |
206148 KB |
Output is correct |
26 |
Correct |
64 ms |
206672 KB |
Output is correct |
27 |
Correct |
70 ms |
206420 KB |
Output is correct |
28 |
Correct |
68 ms |
206624 KB |
Output is correct |
29 |
Correct |
66 ms |
206672 KB |
Output is correct |
30 |
Correct |
64 ms |
206420 KB |
Output is correct |
31 |
Correct |
64 ms |
206416 KB |
Output is correct |
32 |
Correct |
77 ms |
206580 KB |
Output is correct |
33 |
Runtime error |
198 ms |
62608 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
90 ms |
206376 KB |
Output is correct |
6 |
Correct |
29 ms |
205904 KB |
Output is correct |
7 |
Correct |
27 ms |
206176 KB |
Output is correct |
8 |
Correct |
75 ms |
206664 KB |
Output is correct |
9 |
Correct |
27 ms |
205920 KB |
Output is correct |
10 |
Correct |
33 ms |
205916 KB |
Output is correct |
11 |
Correct |
16 ms |
105048 KB |
Output is correct |
12 |
Correct |
64 ms |
206684 KB |
Output is correct |
13 |
Correct |
26 ms |
206172 KB |
Output is correct |
14 |
Correct |
67 ms |
206504 KB |
Output is correct |
15 |
Correct |
27 ms |
206164 KB |
Output is correct |
16 |
Correct |
66 ms |
206420 KB |
Output is correct |
17 |
Correct |
30 ms |
205976 KB |
Output is correct |
18 |
Correct |
14 ms |
109660 KB |
Output is correct |
19 |
Correct |
69 ms |
206388 KB |
Output is correct |
20 |
Correct |
28 ms |
206172 KB |
Output is correct |
21 |
Correct |
25 ms |
206188 KB |
Output is correct |
22 |
Correct |
66 ms |
206264 KB |
Output is correct |
23 |
Correct |
26 ms |
205908 KB |
Output is correct |
24 |
Correct |
65 ms |
206380 KB |
Output is correct |
25 |
Correct |
28 ms |
206148 KB |
Output is correct |
26 |
Correct |
64 ms |
206672 KB |
Output is correct |
27 |
Correct |
70 ms |
206420 KB |
Output is correct |
28 |
Correct |
68 ms |
206624 KB |
Output is correct |
29 |
Correct |
66 ms |
206672 KB |
Output is correct |
30 |
Correct |
64 ms |
206420 KB |
Output is correct |
31 |
Correct |
64 ms |
206416 KB |
Output is correct |
32 |
Correct |
77 ms |
206580 KB |
Output is correct |
33 |
Runtime error |
198 ms |
62608 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |