답안 #485767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485767 2021-11-09T09:53:14 Z milisav Fireworks (APIO16_fireworks) C++14
7 / 100
13 ms 23816 KB
#include<bits/stdc++.h>
#define maxn 1000000
using namespace std;
int n,m;
vector<int> a[maxn];
int p[maxn];
int c[maxn];
long long ans;
long long x[maxn][2];
long long t[maxn];
vector<long long> cur;
void dfs(int u) {
	if(a[u].size()==0) {
		x[u][0]=c[u];
		x[u][1]=c[u];
		return;
	}
	for(auto v:a[u]) {
		dfs(v);
	}
	cur.clear();
	for(auto v:a[u]) {
		cur.push_back(x[v][0]);
		cur.push_back(x[v][1]);
	}
	sort(cur.begin(),cur.end());
	int pos=cur.size()/2-1;
	x[u][0]=cur[pos]+c[u];
	x[u][1]=cur[pos+1]+c[u];
	long long t1=cur[pos];
	long long t2=cur[pos+1];
	long long v1=0,v2=0;
	for(auto v:a[u]) {
		if(t1<x[v][0]) v1+=(x[v][0]-t1);
		if(t1>x[v][1]) v1+=(t1-x[v][1]);
		if(t2<x[v][0]) v2+=(x[v][0]-t2);
		if(t2>x[v][1]) v2+=(t2-x[v][1]);
	}
	assert(v1==v2);
	ans+=v1;
}
int main() {
	scanf("%d %d",&n,&m);
	for(int i=2;i<=n+m;i++) {
		scanf("%d %d",&p[i],&c[i]);
		a[p[i]].push_back(i);
	}
	dfs(1);
	printf("%lld\n",ans);
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d %d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
fireworks.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d %d",&p[i],&c[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23768 KB Output is correct
3 Correct 13 ms 23808 KB Output is correct
4 Correct 11 ms 23800 KB Output is correct
5 Correct 11 ms 23736 KB Output is correct
6 Correct 11 ms 23756 KB Output is correct
7 Correct 11 ms 23756 KB Output is correct
8 Correct 11 ms 23808 KB Output is correct
9 Correct 11 ms 23756 KB Output is correct
10 Correct 11 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 11 ms 23816 KB Output is correct
3 Incorrect 12 ms 23756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23768 KB Output is correct
3 Correct 13 ms 23808 KB Output is correct
4 Correct 11 ms 23800 KB Output is correct
5 Correct 11 ms 23736 KB Output is correct
6 Correct 11 ms 23756 KB Output is correct
7 Correct 11 ms 23756 KB Output is correct
8 Correct 11 ms 23808 KB Output is correct
9 Correct 11 ms 23756 KB Output is correct
10 Correct 11 ms 23756 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 11 ms 23816 KB Output is correct
13 Incorrect 12 ms 23756 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23768 KB Output is correct
3 Correct 13 ms 23808 KB Output is correct
4 Correct 11 ms 23800 KB Output is correct
5 Correct 11 ms 23736 KB Output is correct
6 Correct 11 ms 23756 KB Output is correct
7 Correct 11 ms 23756 KB Output is correct
8 Correct 11 ms 23808 KB Output is correct
9 Correct 11 ms 23756 KB Output is correct
10 Correct 11 ms 23756 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 11 ms 23816 KB Output is correct
13 Incorrect 12 ms 23756 KB Output isn't correct
14 Halted 0 ms 0 KB -