-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf28b.cpp
More file actions
36 lines (33 loc) · 689 Bytes
/
cf28b.cpp
File metadata and controls
36 lines (33 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <cstdio>
#include <cstring>
const int MAX_N = 107;
int n;
int a[MAX_N], b[MAX_N];
bool edge[MAX_N][MAX_N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; ++i) {
scanf("%d", &b[i]);
edge[i][i] = true;
if (i - b[i] >= 1) edge[i][i - b[i]] = true;
if (i + b[i] <= n) edge[i][i + b[i]] = true;
}
for (int k = 1; k <= n; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
edge[i][j] = edge[i][j] | edge[i][k] & edge[k][j] | edge[i][k] & edge[j][k];
}
}
}
for (int i = 1; i <= n; ++i) {
if (!edge[i][a[i]]) {
puts("NO");
return 0;
}
}
puts("YES");
return 0;
}