제출 #111793

#제출 시각아이디문제언어결과실행 시간메모리
111793nxteruFireworks (APIO16_fireworks)C++14
100 / 100
406 ms53004 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
ll n,m,ans,vs[300005];
priority_queue<ll>p[300005];
vector<P>g[300005];
void up(int v,ll c){
	if(p[v].size()==0){
		p[v].push(c);
		p[v].push(c);
	}else{
		ll x=p[v].top();
		p[v].pop();
		ll y=p[v].top();
		p[v].pop();
		p[v].push(x+c);
		p[v].push(y+c);
	}
}
void merge(int x,int y){
	if(p[vs[x]].size()<p[vs[y]].size())swap(x,y);
	int py=y;
	y=vs[y];
	x=vs[x];
	vs[py]=x;
	while(!p[y].empty()){
		p[x].push(p[y].top());
		p[y].pop();
	}
}
void dfs(int v){
	ll s=g[v].size();
	if(s==0)return;
	for(int i=0;i<g[v].size();i++){
		ll u=g[v][i].F,c=g[v][i].S;
		dfs(u);
		up(vs[u],c);
		ans-=p[vs[u]].top();
		merge(v,u);
	}
	for(int i=0;i<s-1;i++){
		ans+=p[vs[v]].top();
		p[vs[v]].pop();
	}
	ans+=p[vs[v]].top();
}
int main(void){
    scanf("%lld%lld",&n,&m);
    n+=m;
    for(int i=0;i<n;i++)vs[i]=i;
    for(int i=1;i<n;i++){
		ll q,c;
		scanf("%lld%lld",&q,&c);
		g[--q].PB(P(i,c));
	}
	dfs(0);
	printf("%lld\n",ans);
}

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

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[v].size();i++){
              ~^~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~
fireworks.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&q,&c);
   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...