제출 #1352999

#제출 시각아이디문제언어결과실행 시간메모리
1352999tsengangFireworks (APIO16_fireworks)C++20
7 / 100
1 ms1860 KiB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
vector<pair<ll,ll>>adj[200005];
vector<ll>v;
vector<ll>sz(200005);
ll calc(ll x,ll p){
	sz[x] = 1;
	for(auto [y,w] : adj[x]){
		if(y!=p){
			sz[x]+=calc(y,x);
		}
	}	
	return sz[x];
}
int main(){
	ll n,m;    
	cin >> n >> m;
	for(ll i = 2; i <= n; i++){
		ll a,c;
		cin >> a >> c;
		adj[a].pb({i,c});
		adj[i].pb({a,c});
	}
	ll ans = 0;
	vector<pair<ll,ll>>bomba;
	for(ll i = n+1; i <= n+m; i++){
		ll a,c;
		cin >> a >> c;
		adj[a].pb({i,c});
		bomba.pb({c,i});
	}
	sort(all(bomba));
	for(ll i = 0; i < bomba.size(); i++){
		ans+= abs(bomba[m/2].ff-bomba[i].ff);
	}
	cout << ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…