QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#715116#9532. 长野原龙势流星群konata28280 146ms9348kbC++20989b2024-11-06 10:30:302024-11-06 10:30:31

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 10:30:31]
  • 评测
  • 测评结果:0
  • 用时:146ms
  • 内存:9348kb
  • [2024-11-06 10:30:30]
  • 提交

answer

// Hydro submission #672ad4c4a059678966633e4e@1730860229100
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
double dp[N];
int n,w[N],sum[N],head[N],ecnt=0;
struct edge {int to,nxt;}e[N<<1];
void add(int u,int v) {e[++ecnt]=(edge){v,head[u]};head[u]=ecnt;}
struct node {
	double x;int y;
	bool operator<(const node &o) const {
		if(x==o.x) return y<o.y;
		return x>o.x;
	}
}tmp[N];
void dfs(int u) {
	for(int i=head[u]; i; i=e[i].nxt) {
		int v=e[i].to;
		dfs(v);
	}
	int tot=0;
	for(int i=head[u]; i; i=e[i].nxt) tmp[++tot]=(node){dp[e[i].to],sum[e[i].to]};
	sort(tmp+1,tmp+tot+1);
	dp[u]=w[u],sum[u]=1;
	for(int i=1; i<=tot; i++) {
		if(tmp[i].x<dp[u]) break;
		dp[u]=(dp[u]*sum[u]+tmp[i].x*tmp[i].y)/(sum[u]+tmp[i].y);
		sum[u]+=tmp[i].y;
	}
}
int main() {
	cin>>n;
	for(int i=2; i<=n; i++) {
		int p;cin>>p;
		add(p,i);
	}
	for(int i=1; i<=n; i++) cin>>w[i];
	dfs(1);
	for(int i=1; i<=n; i++) printf("%.10lf\n",dp[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 7924kb

input:

2000
1 2 2 4 5 2 3 6 4 2 7 2 8 14 8 12 1 14 4 14 8 18 9 2 7 22 20 22 14 29 28 16 6 21 23 6 21 14 13 9 1 4 18 13 2 39 21 33 18 20 38 27 27 1 49 5 51 3 31 24 10 42 2 44 13 9 35 66 27 60 67 59 29 40 53 2 33 43 26 43 62 16 78 45 14 10 73 69 41 35 25 26 2 70 54 1 54 48 5 36 44 28 90 29 51 51 93 82 95 45 ...

output:

878341451.1578947306
879173186.6363636255
848557303.2272727489
912609654.6666666269
872318573.5000000000
816339179.0000000000
850251397.5555555820
858217450.2352941036
812960827.3636363745
866017059.7777777910
693335785.3750000000
921947345.6666666269
994728511.5000000000
950304719.0000000000
808673...

result:

wrong answer 1st numbers differ - expected: '883838885.9230770', found: '878341451.1578947', error = '0.0062200'

Subtask #2:

score: 0
Wrong Answer

Test #32:

score: 0
Wrong Answer
time: 146ms
memory: 9348kb

input:

200000
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...

output:

686880396.2941176891
563544686.1428571939
693705743.1515151262
618391182.7999999523
746642876.0000000000
806376230.0000000000
698219365.7419354916
699584745.7500000000
617426841.1935484409
700325141.0000000000
691212027.0000000000
722381415.0000000000
631630674.3333333731
857291392.5000000000
709515...

result:

wrong answer 1st numbers differ - expected: '792545632.4154930', found: '686880396.2941177', error = '0.1333239'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%