#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && (c != '-')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int N = 1e6 + 10;
int n, m, a, b, c, d;
vector<int> e[N];
int fa[N], siz[N], dep[N];
inline void dfs(int u) {
  siz[u] = (((int)(e[u]).size()) == 1), dep[u] = dep[fa[u]] + 1;
  for (auto v : e[u])
    if (v != fa[u]) fa[v] = u, dfs(v), siz[u] += siz[v];
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  if (dep[x] > dep[y])
    while (dep[x] > dep[y]) x = fa[x];
  if (x == y) return x;
  while (x != y) x = fa[x], y = fa[y];
  return x;
}
inline int jump(int u, int k) {
  for (register int i = (1); i <= (k); i++) u = fa[u];
  return u;
}
vector<int> v1, v2, v3;
bool vis[N];
inline void add(vector<int> &v, int x, int y) {
  if (x == y) return;
  int las = x;
  x = fa[x];
  while (x != y) {
    for (auto son : e[x])
      if (son != fa[x] && son != las && !vis[son])
        v.push_back(siz[son]), vis[son] = 1;
    las = x, x = fa[x];
  }
}
int cnt[N];
inline bitset<N / 2> work(vector<int> v) {
  vector<int> v2;
  memset((cnt), (0), sizeof(cnt));
  int mx = 0;
  for (auto i : v) cnt[i]++, mx = max(mx, i);
  for (register int i = (1); i <= (mx); i++) {
    int k = 1, s = cnt[i], a = i;
    while (k <= s) v2.push_back(k * a), s -= k, k *= 2;
    if (s > 0) v2.push_back(s * a);
  }
  bitset<N / 2> f;
  f[0] = 1;
  for (auto i : v2) f = f | (f << i);
  return f;
}
inline bool check(int a, int b, int c) {
  memset((vis), (0), sizeof(vis));
  vis[jump(a, dep[a] - 2)] = vis[jump(b, dep[b] - 2)] =
      vis[jump(c, dep[c] - 2)] = 1;
  vector<int> v;
  add(v, a, 1), add(v, c, 1);
  for (auto son : e[1])
    if (!vis[son]) v.push_back(siz[son]);
  auto f = work(v);
  if (m / 2 - 1 - siz[b] >= 0 && f[m / 2 - 1 - siz[b]]) return 1;
  return 0;
}
int main() {
  n = read(), a = read(), b = read(), c = read(), d = read();
  for (register int i = (2); i <= (n); i++) {
    int fa = read();
    e[fa].push_back(i), e[i].push_back(fa);
  }
  dfs(1), m = siz[1];
  if ((m & 1) || lca(a, b) != 1 || lca(c, d) != 1) return puts("NO"), 0;
  if (check(a, c, b) && check(c, b, d)) return puts("YES"), 0;
  if (check(a, d, b) && check(c, b, d)) return puts("YES"), 0;
  puts("NO");
}
