#include <bits/stdc++.h>
using namespace std;
inline void rd(int &res) {
  res = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do res = (res << 1) + (res << 3) + (c ^ 48);
  while (c = getchar(), c >= 48);
}
const int M = 5005;
int m = 0, n, f[M], fa[M], sz[M], head[M], to[M], ec = 2, nxt[M];
int A, B, C, D;
bitset<M> s;
void ins(int a, int b) {
  to[ec] = b;
  nxt[ec] = head[a];
  head[a] = ec++;
}
bool chk(int a, int b) {
  s.reset();
  s[0] = 1;
  int x, y, i, j;
  for (y = a, x = fa[a]; x; y = x, x = fa[x]) {
    for (i = head[x]; i; i = nxt[i]) {
      if (to[i] != y) s |= s << sz[to[i]];
    }
  }
  for (y = b, x = fa[b]; x != 1; y = x, x = fa[x]) {
    for (i = head[x]; i; i = nxt[i]) {
      if (to[i] != y) s |= s << sz[to[i]];
    }
  }
  return s[sz[1] / 2 - 1];
}
void solve() {
  int i, j, k;
  rd(n);
  rd(A), rd(B), rd(C), rd(D);
  for (i = 2; i <= n; i++) rd(fa[i]), ins(fa[i], i);
  for (i = n; i >= 1; i--) {
    if (!sz[i]) sz[i] = 1;
    sz[fa[i]] += sz[i];
  }
  if ((sz[1] & 1) == 0 && chk(A, B) && chk(C, D))
    puts("YES");
  else
    puts("NO");
}
int main() {
  solve();
  return 0;
}
