#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;
long long depth[200013];
//int visit[200013];
long long bas[200013];
long long fib[200013];
vector< int > tut;
vector< vector<long long> > vec;
vector< vector<long long> > grp;
void dfs(int bas){
vec[bas].pb(bas);
for(int i=0;i<grp[bas].size();i++){
/*for(int j=0;j<vec[bas].size();j++){
vec[grp[bas][i]].pb(vec[bas][j]);
}*/
vec[grp[bas][i]]=vec[bas];
depth[grp[bas][i]]=depth[bas]+1;
dfs(grp[bas][i]);
}
if(grp[bas].size()==0){
tut.pb(bas);
}
return;
}
int main(){
long long n;
cin>>n;
for(int i=0;i<=n;i++){
vector<long long> aaa;
vec.pb(aaa);
grp.pb(aaa);
}
for(long long i=2;i<=n;i++){
int k;
sc(k);
grp[k].pb(i);
}
fib[0]=1;
fib[1]=1;
for(int i=2;i<=200000;i++){
fib[i]=fib[i-1]+fib[i-2];
}
dfs(1);
for(int i=0;i<tut.size();i++){
int p=tut[i];
for(int j=0;j<vec[p].size();j++){
int g=vec[p][j];
long long fark=depth[p]-depth[g]+1;
if(fark>1){
fark++;
}
bas[g]+=fib[fark];
}
}
for(int i=1;i<=n;i++){
cout<<bas[i]<<" ";
}
return 0;
}
Compilation message
birokracija.cpp: In function 'void dfs(int)':
birokracija.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<grp[bas].size();i++){
~^~~~~~~~~~~~~~~~
birokracija.cpp: In function 'int main()':
birokracija.cpp:68:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tut.size();i++){
~^~~~~~~~~~~
birokracija.cpp:70:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<vec[p].size();j++){
~^~~~~~~~~~~~~~
birokracija.cpp:3:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define sc(a) scanf("%d",&a)
~~~~~^~~~~~~~~
birokracija.cpp:59:3: note: in expansion of macro 'sc'
sc(k);
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1912 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1912 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
7084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
21108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
273 ms |
60744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
272 ms |
57924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
270 ms |
56332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |