Submission #85736

# Submission time Handle Problem Language Result Execution time Memory
85736 2018-11-21T12:19:01 Z heon Birokracija (COCI18_birokracija) C++11
70 / 100
359 ms 36084 KB
#include<bits/stdc++.h>

using namespace std;

vector <int> g[200005];
map <int,int> mp;

int dfs(int x, int parent){
	int res = 1;
	for(auto y : g[x]){
		res += dfs(y, x);
	}
	mp[x] += res;
	if(x != 1) mp[parent] += mp[x]; 
	return res;
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	for(int i = 2; i <= n; i++){
		int x;
		cin >> x;
		g[x].push_back(i);
		//g[i].push_back(x);
	}
	dfs(1, -1);
	for(int i = 1; i <= n; i++) cout << mp[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5240 KB Output is correct
2 Correct 7 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 6 ms 5304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5312 KB Output is correct
2 Correct 6 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6784 KB Output is correct
2 Correct 24 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 10740 KB Output is correct
2 Correct 64 ms 11480 KB Output is correct
3 Correct 64 ms 13156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 21108 KB Output is correct
2 Incorrect 184 ms 25148 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 304 ms 25148 KB Output is correct
2 Correct 179 ms 26248 KB Output is correct
3 Incorrect 165 ms 30180 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 314 ms 30180 KB Output is correct
2 Correct 178 ms 30228 KB Output is correct
3 Incorrect 173 ms 36084 KB Output isn't correct