#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
#define ll long long
const int mxn = 3e5+10;
int N,M;
vector<pii> tree[mxn];
int par[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M;
for(int i = 2;i<=N+M;i++){
int p,c;
cin>>p>>c;
par[i] = p;
tree[p].push_back(pii(i,c));
}
sort(tree[1].begin(),tree[1].end(),[](pii a,pii b){return a.sc<b.sc;});
int tar = tree[1][tree[1].size()>>1].sc;
ll ans = 0;
for(auto &i:tree[1])ans += abs(tar-i.sc);
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7256 KB |
Output is correct |
2 |
Correct |
3 ms |
7260 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7516 KB |
Output is correct |
5 |
Correct |
3 ms |
7260 KB |
Output is correct |
6 |
Correct |
4 ms |
7672 KB |
Output is correct |
7 |
Correct |
4 ms |
7260 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
4 ms |
7256 KB |
Output is correct |
10 |
Correct |
3 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
7256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7256 KB |
Output is correct |
2 |
Correct |
3 ms |
7260 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7516 KB |
Output is correct |
5 |
Correct |
3 ms |
7260 KB |
Output is correct |
6 |
Correct |
4 ms |
7672 KB |
Output is correct |
7 |
Correct |
4 ms |
7260 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
4 ms |
7256 KB |
Output is correct |
10 |
Correct |
3 ms |
7260 KB |
Output is correct |
11 |
Incorrect |
3 ms |
7256 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7256 KB |
Output is correct |
2 |
Correct |
3 ms |
7260 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7516 KB |
Output is correct |
5 |
Correct |
3 ms |
7260 KB |
Output is correct |
6 |
Correct |
4 ms |
7672 KB |
Output is correct |
7 |
Correct |
4 ms |
7260 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
4 ms |
7256 KB |
Output is correct |
10 |
Correct |
3 ms |
7260 KB |
Output is correct |
11 |
Incorrect |
3 ms |
7256 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |