#include <iostream>
using namespace std;
int cs[210000];
int col[210000];
int par[210000];
int main()
{
int N;
cin >> N;
int i;
col[0]=0;
par[0]=-1;
for(i=1;i<=N;i++)
{
cin >> par[i];
int a=i;
col[i]=0;
cs[par[i]]++;
int ans=0;
while(a>=0)
{
cs[par[a]]-=1-col[a];
if(!cs[a])
{
if(col[a]==1)
ans++;
col[a]=0;
cs[par[a]]++;
}
else
{
if(col[a]==0)
ans++;
col[a]=1;
}
a=par[a];
}
cout << ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
8 |
Correct |
23 ms |
392 KB |
Output is correct |
9 |
Correct |
180 ms |
388 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
380 KB |
Output is correct |
12 |
Correct |
20 ms |
484 KB |
Output is correct |
13 |
Correct |
35 ms |
436 KB |
Output is correct |
14 |
Correct |
41 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
8 |
Correct |
23 ms |
392 KB |
Output is correct |
9 |
Correct |
180 ms |
388 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
380 KB |
Output is correct |
12 |
Correct |
20 ms |
484 KB |
Output is correct |
13 |
Correct |
35 ms |
436 KB |
Output is correct |
14 |
Correct |
41 ms |
376 KB |
Output is correct |
15 |
Correct |
230 ms |
1564 KB |
Output is correct |
16 |
Execution timed out |
1086 ms |
600 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
444 ms |
3036 KB |
Output is correct |
2 |
Correct |
480 ms |
2508 KB |
Output is correct |
3 |
Correct |
349 ms |
1836 KB |
Output is correct |
4 |
Correct |
439 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
8 |
Correct |
23 ms |
392 KB |
Output is correct |
9 |
Correct |
180 ms |
388 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
380 KB |
Output is correct |
12 |
Correct |
20 ms |
484 KB |
Output is correct |
13 |
Correct |
35 ms |
436 KB |
Output is correct |
14 |
Correct |
41 ms |
376 KB |
Output is correct |
15 |
Correct |
230 ms |
1564 KB |
Output is correct |
16 |
Execution timed out |
1086 ms |
600 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |