/* -*- coding: utf-8 -*- * * 74.cc: No.74 貯金箱の退屈 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; /* typedef */ struct UFT { int links[MAX_N], ranks[MAX_N], sizes[MAX_N]; void clear(int n) { for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1; } UFT() {} UFT(int n) { clear(n); } int root(int i) { int i0 = i; while (links[i0] != i0) i0 = links[i0]; return (links[i] = i0); } int rank(int i) { return ranks[root(i)]; } int size(int i) { return sizes[root(i)]; } bool same(int i, int j) { return root(i) == root(j); } int merge(int i0, int i1) { int r0 = root(i0), r1 = root(i1), mr; if (r0 == r1) return r0; if (ranks[r0] == ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; ranks[r0]++; mr = r0; } else if (ranks[r0] > ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; mr = r0; } else { links[r0] = r1; sizes[r1] += sizes[r0]; mr = r1; } return mr; } }; /* global variables */ int ds[MAX_N], wis[MAX_N], cnts[MAX_N]; bool ones[MAX_N]; UFT uft; /* subroutines */ /* main */ int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> ds[i]; for (int i = 0; i < n; i++) cin >> wis[i]; uft.clear(n); for (int i = 0; i < n; i++) { int i0 = (i + ds[i]) % n; int i1 = (i - ds[i] + 1000 * n) % n; //printf("%d: (%d,%d)\n", i, i0, i1); if (i0 == i1) ones[i] = true; else uft.merge(i0, i1); } for (int i = 0; i < n; i++) { if (ones[i]) ones[uft.root(i)] = true; if (wis[i] == 0) cnts[uft.root(i)]++; } bool ok = true; for (int i = 0; i < n; i++) if (uft.root(i) == i && ! ones[i] && (cnts[i] & 1) != 0) { ok = false; break; } cout << (ok ? "Yes" : "No") << endl; return 0; }