답안 #254831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254831 2020-07-30T17:29:03 Z errorgorn Fireworks (APIO16_fireworks) C++14
26 / 100
14 ms 16896 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
 
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
 
ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}
 
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
int n,m;
vector<int> al[300005];
ll d[300005];
 
ll w[300005];
priority_queue<ll> pq[300005];
 
void dfs(int i){
	if (i>n){
		pq[i].push(0);
		pq[i].push(0);
	}
	else{
		vector<int> tops;
		
		int grad=-1;
		for (auto &it:al[i]){
			dfs(it);
			d[i]+=d[it];
			grad++;
			
			tops.push_back(pq[it].top());
			if (pq[i].empty()) swap(pq[i],pq[it]);
			else{
				if (sz(pq[i])<sz(pq[it])) swap(pq[i],pq[it]);
				
				while (!pq[it].empty()){
					pq[i].push(pq[it].top());
					pq[it].pop();
				}
			}
		}
		
		for (auto &it:tops) d[i]+=pq[i].top()-it;
		while (grad){
			ll temp=pq[i].top();
			pq[i].pop();
			d[i]-=grad*(temp-pq[i].top());
			grad--;
		}
	}
	
	ll t1,t2;
	t1=pq[i].top(),pq[i].pop();
	t2=pq[i].top(),pq[i].pop();
	pq[i].push(t1+w[i]);
	pq[i].push(t2+w[i]);
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>m;
	
	int a,b;
	rep(x,2,n+m+1){
		cin>>a>>b;
		al[a].push_back(x);
		w[x]=b;
	}
	
	dfs(1);
	cout<<d[1]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 10 ms 16768 KB Output is correct
4 Correct 14 ms 16768 KB Output is correct
5 Correct 10 ms 16768 KB Output is correct
6 Correct 10 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 11 ms 16768 KB Output is correct
9 Correct 11 ms 16768 KB Output is correct
10 Correct 10 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 10 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 10 ms 16768 KB Output is correct
6 Correct 10 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 10 ms 16768 KB Output is correct
9 Correct 10 ms 16768 KB Output is correct
10 Correct 10 ms 16768 KB Output is correct
11 Correct 10 ms 16768 KB Output is correct
12 Correct 11 ms 16896 KB Output is correct
13 Correct 10 ms 16768 KB Output is correct
14 Correct 10 ms 16896 KB Output is correct
15 Correct 10 ms 16768 KB Output is correct
16 Correct 10 ms 16768 KB Output is correct
17 Correct 10 ms 16768 KB Output is correct
18 Correct 10 ms 16768 KB Output is correct
19 Correct 11 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 10 ms 16768 KB Output is correct
4 Correct 14 ms 16768 KB Output is correct
5 Correct 10 ms 16768 KB Output is correct
6 Correct 10 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 11 ms 16768 KB Output is correct
9 Correct 11 ms 16768 KB Output is correct
10 Correct 10 ms 16768 KB Output is correct
11 Correct 10 ms 16768 KB Output is correct
12 Correct 10 ms 16768 KB Output is correct
13 Correct 10 ms 16768 KB Output is correct
14 Correct 10 ms 16768 KB Output is correct
15 Correct 10 ms 16768 KB Output is correct
16 Correct 10 ms 16768 KB Output is correct
17 Correct 10 ms 16768 KB Output is correct
18 Correct 10 ms 16768 KB Output is correct
19 Correct 10 ms 16768 KB Output is correct
20 Correct 10 ms 16768 KB Output is correct
21 Correct 10 ms 16768 KB Output is correct
22 Correct 11 ms 16896 KB Output is correct
23 Correct 10 ms 16768 KB Output is correct
24 Correct 10 ms 16896 KB Output is correct
25 Correct 10 ms 16768 KB Output is correct
26 Correct 10 ms 16768 KB Output is correct
27 Correct 10 ms 16768 KB Output is correct
28 Correct 10 ms 16768 KB Output is correct
29 Correct 11 ms 16768 KB Output is correct
30 Incorrect 10 ms 16768 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 10 ms 16768 KB Output is correct
4 Correct 14 ms 16768 KB Output is correct
5 Correct 10 ms 16768 KB Output is correct
6 Correct 10 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 11 ms 16768 KB Output is correct
9 Correct 11 ms 16768 KB Output is correct
10 Correct 10 ms 16768 KB Output is correct
11 Correct 10 ms 16768 KB Output is correct
12 Correct 10 ms 16768 KB Output is correct
13 Correct 10 ms 16768 KB Output is correct
14 Correct 10 ms 16768 KB Output is correct
15 Correct 10 ms 16768 KB Output is correct
16 Correct 10 ms 16768 KB Output is correct
17 Correct 10 ms 16768 KB Output is correct
18 Correct 10 ms 16768 KB Output is correct
19 Correct 10 ms 16768 KB Output is correct
20 Correct 10 ms 16768 KB Output is correct
21 Correct 10 ms 16768 KB Output is correct
22 Correct 11 ms 16896 KB Output is correct
23 Correct 10 ms 16768 KB Output is correct
24 Correct 10 ms 16896 KB Output is correct
25 Correct 10 ms 16768 KB Output is correct
26 Correct 10 ms 16768 KB Output is correct
27 Correct 10 ms 16768 KB Output is correct
28 Correct 10 ms 16768 KB Output is correct
29 Correct 11 ms 16768 KB Output is correct
30 Incorrect 10 ms 16768 KB Output isn't correct
31 Halted 0 ms 0 KB -