General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
19118998 Contestant:
Jefe
696B - 10 GNU C++11 Time limit exceeded on test 36 1000 ms 4220 KB 2016-07-14 20:05:36 2016-07-14 22:14:15
 
 
→ Source
#include <bits/stdc++.h>
using namespace std;

const int MAX=100010;
int H[MAX];
int P[MAX];
int S[MAX];
vector <int> E[MAX];
double R[MAX];

void dfs(int x){
	int sum=0;
	for(int y: E[x] ){
		sum++;
		dfs(y);
		sum+=S[y];
	}
	S[x]=sum;
}

void dfs2(int x){
	if(x!=1){
		double res=0;
		for(int y: E[P[x]]){
			if(y!=x) res+=S[y]+1;
		}
		res/=2;
		res+=R[P[x]]+1;
		R[x]=res;
	}
	for(int y: E[x]) dfs2(y);
}



int main(){
	int n;
	scanf("%d",&n);
	P[1]=1;
	R[1]=1;
	for(int i=2;i<=n;i++){
		scanf("%d",&P[i]);
		E[P[i]].push_back(i);
	}
	dfs(1);
	dfs2(1);
	for(int i=1;i<=n;i++){
		printf("%f\n",R[i]);
	}
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details