제출 #403726

#제출 시각아이디문제언어결과실행 시간메모리
403726CursedCodeFireworks (APIO16_fireworks)C++14
7 / 100
1 ms332 KiB
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;

const int maxn = 300003;

priority_queue<long long> *Q[maxn];
int N,M,V,P[maxn],C[maxn],D[maxn]; long long E[maxn];

int main()
{
	scanf ("%d %d",&N,&M);
	V = N + M;
	if(N != 1){
		return 0;
	}
	for (int i=2;i<=V;i++) scanf ("%d %d",&P[i],&C[i]);
	for (int i=1;i<=V;i++) Q[i] = new priority_queue<long long>;

	for (int i=V;i>=2;i--){
		long long p = 0, q = 0;
		if (D[i]){
			for (int j=1;j<D[i];j++){
				E[i] += Q[i]->top(); Q[i]->pop();
			}
			p = Q[i]->top(); Q[i]->pop();
			q = Q[i]->top(); Q[i]->pop();
		}
		Q[i]->push(p+C[i]);
		Q[i]->push(q+C[i]);
		E[i] -= C[i];

		priority_queue<long long> *&a = Q[i], *&b = Q[P[i]];
		if (a->size() > b->size()) swap(a,b);
		while (!a->empty()){
			b->push(a->top()); a->pop();
		}
		E[P[i]] += E[i];
		D[P[i]]++;
	}

	long long ans = E[1];
	for (int i=0;i<D[1];i++){
		ans += Q[1]->top(); Q[1]->pop();
	}
	printf ("%lld\n",ans);

	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

fireworks.cpp: In function 'int main()':
fireworks.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf ("%d %d",&N,&M);
      |  ~~~~~~^~~~~~~~~~~~~~~
fireworks.cpp:18:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  for (int i=2;i<=V;i++) scanf ("%d %d",&P[i],&C[i]);
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...