Submission #85738

# Submission time Handle Problem Language Result Execution time Memory
85738 2018-11-21T12:19:50 Z heon Birokracija (COCI18_birokracija) C++11
100 / 100
346 ms 39928 KB
#include<bits/stdc++.h>

using namespace std;

vector <int> g[200005];
map <int,long long> 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 6 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5248 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5288 KB Output is correct
2 Correct 7 ms 5304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5308 KB Output is correct
2 Correct 6 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 7024 KB Output is correct
2 Correct 25 ms 7636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 11276 KB Output is correct
2 Correct 63 ms 11548 KB Output is correct
3 Correct 60 ms 12840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 335 ms 21604 KB Output is correct
2 Correct 186 ms 24448 KB Output is correct
3 Correct 264 ms 39928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 39928 KB Output is correct
2 Correct 189 ms 39928 KB Output is correct
3 Correct 173 ms 39928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 39928 KB Output is correct
2 Correct 182 ms 39928 KB Output is correct
3 Correct 164 ms 39928 KB Output is correct