Submission #1018513

# Submission time Handle Problem Language Result Execution time Memory
1018513 2024-07-10T06:24:33 Z vjudge1 Birokracija (COCI18_birokracija) C++17
100 / 100
102 ms 28788 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int M = 2e5 + 1;

int subt[M],ans[M];
vector<int> nei[M];

void dfs(int u)
{
	subt[u]=1;
	for (int i:nei[u])
	{
		dfs(i);
		ans[u]+=ans[i];
		subt[u]+=subt[i];
	}
	ans[u]+=subt[u];
}

signed main()
{
	int n;
	cin>>n;
	for (int i=2;i<=n;i++)
	{
		int u;
		cin>>u;
		nei[u].push_back(i);
	}
	dfs(1);
	for (int i=1;i<=n;i++)
		cout<<ans[i]<<' ';
	cout<<endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7256 KB Output is correct
2 Correct 10 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 8536 KB Output is correct
2 Correct 19 ms 8796 KB Output is correct
3 Correct 20 ms 10076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 12368 KB Output is correct
2 Correct 55 ms 14724 KB Output is correct
3 Correct 70 ms 28788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 12220 KB Output is correct
2 Correct 68 ms 13648 KB Output is correct
3 Correct 58 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 12112 KB Output is correct
2 Correct 61 ms 13904 KB Output is correct
3 Correct 60 ms 18420 KB Output is correct