#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline T qmax(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T b) {
  if (a > b) a = b;
}
template <typename T>
inline void getmax(T &a, const T b) {
  if (a < b) a = b;
}
inline void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = (int)1e9 + 7;
const long long linf = (long long)1e17 + 7;
const int N = 5005, logN = 21;
int v[N], nxt[N];
int head[N], dep[N], par[N][logN], sz[N];
bool kicked[N];
int n;
inline void addedge(int p, int x, int y) {
  v[p] = y, nxt[p] = head[x], head[x] = p;
}
inline void init(int u, int p) {
  dep[u] = dep[p] + 1;
  par[u][0] = p;
  if (!head[u]) ++sz[u];
  for (int e = head[u]; e; e = nxt[e]) {
    init(v[e], u);
    sz[u] += sz[v[e]];
  }
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) return lca(y, x);
  for (int i = logN - 1; i >= 0; --i) {
    if (dep[x] - dep[y] >> i & 1) x = par[x][i];
  }
  if (x == y) return x;
  for (int i = logN - 1; i >= 0; --i) {
    if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
  }
  return par[x][0];
}
inline bool chk(const vector<int> &a, int tot) {
  static bool f[N];
  memset(f, 0, sizeof(bool) * (tot + 1));
  f[0] = 1;
  for (int i = 0; i < a.size(); ++i) {
    for (int j = tot; j >= a[i]; --j) f[j] |= f[j - a[i]];
  }
  return f[tot];
}
int a, b, c, d;
int main() {
  scanf("%d", &n);
  scanf("%d%d%d%d", &a, &b, &c, &d);
  for (register int(i) = (2); (i) <= (n); ++(i)) {
    int p;
    scanf("%d", &p);
    addedge(i - 1, p, i);
  }
  init(1, 0);
  if (sz[1] & 1) return puts("NO"), 0;
  for (register int(i) = (1); (i) <= (logN - 1); ++(i)) {
    for (register int(j) = (1); (j) <= (n); ++(j)) {
      par[j][i] = par[par[j][i - 1]][i - 1];
    }
  }
  {
    int anc = lca(a, b);
    vector<int> all;
    if (lca(anc, c) != anc) return puts("NO"), 0;
    memset(kicked, false, sizeof(kicked));
    kicked[a] = true;
    for (int t = a, p = par[t][0]; p != anc; t = p, p = par[t][0]) {
      kicked[p] = true;
      for (int e = head[p]; e; e = nxt[e]) {
        if (v[e] == t) continue;
        all.push_back(sz[v[e]]);
      }
    }
    kicked[b] = true;
    for (int t = b, p = par[t][0]; p != anc; t = p, p = par[t][0]) {
      kicked[p] = true;
      for (int e = head[p]; e; e = nxt[e]) {
        if (v[e] == t) continue;
        all.push_back(sz[v[e]]);
      }
    }
    for (int t = c; t != anc; t = par[t][0]) kicked[t] = true;
    for (int e = head[anc]; e; e = nxt[e]) {
      if (kicked[v[e]]) continue;
      all.push_back(sz[v[e]]);
    }
    if (!chk(all, sz[1] / 2 - 1)) return puts("NO"), 0;
  }
  {
    int anc = lca(c, d);
    vector<int> all;
    if (lca(anc, b) != anc) return puts("NO"), 0;
    memset(kicked, false, sizeof(kicked));
    kicked[c] = true;
    for (int t = c, p = par[t][0]; p != anc; t = p, p = par[t][0]) {
      kicked[p] = true;
      for (int e = head[p]; e; e = nxt[e]) {
        if (v[e] == t) continue;
        all.push_back(sz[v[e]]);
      }
    }
    kicked[d] = true;
    for (int t = d, p = par[t][0]; p != anc; t = p, p = par[t][0]) {
      kicked[p] = true;
      for (int e = head[p]; e; e = nxt[e]) {
        if (v[e] == t) continue;
        all.push_back(sz[v[e]]);
      }
    }
    for (int t = b; t != anc; t = par[t][0]) kicked[t] = true;
    for (int e = head[anc]; e; e = nxt[e]) {
      if (kicked[v[e]]) continue;
      all.push_back(sz[v[e]]);
    }
    if (!chk(all, sz[1] / 2 - 1)) return puts("NO"), 0;
  }
  return puts("YES"), 0;
}
