Submission #83147

# Submission time Handle Problem Language Result Execution time Memory
83147 2018-11-05T18:34:17 Z sams Birokracija (COCI18_birokracija) C++14
100 / 100
208 ms 29084 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int MAXN=2e5+10;

int n, m;
int in[MAXN], qc[MAXN];
ll resposta[MAXN];
vector <int> graph[MAXN];

int dfs(int u, int f){

	
	for(int v: graph[u]){
		if(v!=f){

			int qv=dfs(v, u);
			qc[u]+=qv;
			resposta[u]+=resposta[v]+qv;
		}
	}

	resposta[u]++;
	qc[u]++;
	return qc[u];
}

int main(){
	
	cin >> n;

	for(int i=2;i<=n;++i){	
		cin >> in[i];
		graph[i].push_back(in[i]);
		graph[in[i]].push_back(i);
	}

	dfs(1, 1);

	for(int i=1;i<=n;++i){
		cout << resposta[i] << " \n"[i==n];
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5244 KB Output is correct
2 Correct 6 ms 5244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5244 KB Output is correct
2 Correct 6 ms 5244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5244 KB Output is correct
2 Correct 6 ms 5288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6184 KB Output is correct
2 Correct 31 ms 6568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 8840 KB Output is correct
2 Correct 52 ms 8840 KB Output is correct
3 Correct 61 ms 9988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 208 ms 15344 KB Output is correct
2 Correct 142 ms 17052 KB Output is correct
3 Correct 155 ms 29084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 29084 KB Output is correct
2 Correct 150 ms 29084 KB Output is correct
3 Correct 166 ms 29084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 29084 KB Output is correct
2 Correct 154 ms 29084 KB Output is correct
3 Correct 144 ms 29084 KB Output is correct