#include <bits/stdc++.h>
using namespace std;
vector<int> A[2020];
vector<int> B[2020];
bool vA[2020][2020];
bool vB[2020][2020];
void dfsA(int x)
{
vA[x][x] = true;
for(auto y : A[x])
{
dfsA(y);
for(int i = 0; i < 2020; ++i)
if(vA[y][i]) vA[x][i] = true;
}
}
void dfsB(int x)
{
vB[x][x] = true;
for(auto y : B[x])
{
dfsB(y);
for(int i = 0; i < 2020; ++i)
if(vB[y][i]) vB[x][i] = true;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("in.txt", "r", stdin);
int n; cin >> n;
for(int i = 1; i < n; ++i)
{
int x; cin >> x; --x;
A[x].push_back(i);
}
for(int i = 1; i < n; ++i)
{
int x; cin >> x; --x;
B[x].push_back(i);
}
dfsA(0);
dfsB(0);
for(int i = 0; i < n; ++i)
{
int cnt = -1;
for(int j = 0; j < n; ++j) if(vA[i][j] && vB[i][j]) ++cnt;
cout << cnt << ' ';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
16 ms |
4436 KB |
Output is correct |
9 |
Correct |
11 ms |
4428 KB |
Output is correct |
10 |
Correct |
12 ms |
4412 KB |
Output is correct |
11 |
Correct |
9 ms |
4428 KB |
Output is correct |
12 |
Correct |
12 ms |
4496 KB |
Output is correct |
13 |
Correct |
12 ms |
4428 KB |
Output is correct |
14 |
Correct |
13 ms |
4428 KB |
Output is correct |
15 |
Correct |
26 ms |
8380 KB |
Output is correct |
16 |
Correct |
36 ms |
8368 KB |
Output is correct |
17 |
Correct |
31 ms |
8396 KB |
Output is correct |
18 |
Correct |
19 ms |
8396 KB |
Output is correct |
19 |
Correct |
34 ms |
8564 KB |
Output is correct |
20 |
Correct |
37 ms |
8564 KB |
Output is correct |
21 |
Correct |
35 ms |
8524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
16 ms |
4436 KB |
Output is correct |
9 |
Correct |
11 ms |
4428 KB |
Output is correct |
10 |
Correct |
12 ms |
4412 KB |
Output is correct |
11 |
Correct |
9 ms |
4428 KB |
Output is correct |
12 |
Correct |
12 ms |
4496 KB |
Output is correct |
13 |
Correct |
12 ms |
4428 KB |
Output is correct |
14 |
Correct |
13 ms |
4428 KB |
Output is correct |
15 |
Correct |
26 ms |
8380 KB |
Output is correct |
16 |
Correct |
36 ms |
8368 KB |
Output is correct |
17 |
Correct |
31 ms |
8396 KB |
Output is correct |
18 |
Correct |
19 ms |
8396 KB |
Output is correct |
19 |
Correct |
34 ms |
8564 KB |
Output is correct |
20 |
Correct |
37 ms |
8564 KB |
Output is correct |
21 |
Correct |
35 ms |
8524 KB |
Output is correct |
22 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |