Submission #168315

# Submission time Handle Problem Language Result Execution time Memory
168315 2019-12-12T11:26:40 Z muhi1112 Birokracija (COCI18_birokracija) C++17
70 / 100
40 ms 6520 KB
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define int long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=1e5+5;

int n,p[N],dp[N];
vector<int>v[N];

pair<int,int> dfs(int x){
	int ans=0;
	int child=0;
	for(auto i:v[x]){
		if(i!=p[i]){
			pair<int,int>k=dfs(i);
			ans+=k.f1;
			child+=k.s2;
		}
	}
	//cout<<x<<" "<<ans<<" "<<child<<endl;
	dp[x]=ans+child+1;
	pair<int,int>sa={ans+child+1,child+1};
	return sa;
}

int32_t main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	p[1]=1;
	for(int i=2;i<=n;i++){
		cin>>p[i];
		v[p[i]].pb(i);
	}
	dfs(1);
	for(int i=1;i<=n;i++){
		cout<<dp[i]<<" ";
	}

return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3448 KB Output is correct
2 Correct 11 ms 3704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5240 KB Output is correct
2 Correct 25 ms 5624 KB Output is correct
3 Correct 25 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 6320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 6264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 6328 KB Output isn't correct
2 Halted 0 ms 0 KB -