#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int w = 1, s = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return w * s;
}
struct node {
  int to, next;
} e[1010010];
bitset<5001> bt;
int h[1001010], tot, n, a, b, c, d, sz[1010100], a1, b1, c1, d1, all, fll = 0;
inline void add(int from, int to) {
  e[++tot].next = h[from];
  h[from] = tot;
  e[tot].to = to;
}
inline void DFS(int now, int ffa, int t) {
  int fl = 1;
  for (register int i = h[now]; i; i = e[i].next) {
    int to = e[i].to;
    if (to == ffa) continue;
    DFS(to, now, t);
    fl = 0;
  }
  if (fl) {
    sz[t]++;
    ++all;
    if (now == a) a1 = t, fll = 1;
    if (now == b) b1 = t, fll = 1;
    if (now == c) c1 = t, fll = 1;
    if (now == d) d1 = t, fll = 1;
  }
}
int main() {
  bt[0] = 1;
  n = read();
  cin >> a >> b >> c >> d;
  for (register int i = 2; i <= n; ++i) {
    int x = read();
    add(x, i);
  }
  int S = 1;
  for (register int i = h[S]; i; i = e[i].next) {
    int to = e[i].to;
    fll = 0;
    DFS(to, S, to);
    if (!fll) bt |= bt << sz[to];
  }
  if (all & 1) {
    cout << "NO\n";
    exit(0);
  }
  bitset<5001> o1 = bt, o2 = bt;
  for (register int i = 0; i < sz[a1]; ++i) o1 |= o1 << i;
  for (register int i = 0; i < sz[b1]; ++i) o1 |= o1 << i;
  for (register int i = 0; i < sz[c1]; ++i) o2 |= o2 << i;
  for (register int i = 0; i < sz[d1]; ++i) o2 |= o2 << i;
  int hf = all / 2 - 1;
  if ((sz[c1] <= hf) && o1[hf - sz[c1]] && (sz[b1] <= hf) && o2[hf - sz[b1]]) {
    cout << "YES\n";
    exit(0);
  }
  if ((sz[d1] <= hf) && o1[hf - sz[d1]] && (sz[b1] <= hf) && o2[hf - sz[b1]]) {
    cout << "YES\n";
    exit(0);
  }
  cout << "NO\n";
  return 0;
}
