#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long linf = (long long)1e18;
const double eps = (double)1e-8;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
int rucksack(vector<int> &a, int goal) {
  int n = (int)a.size();
  int d[2][5005];
  int tv, tt;
  memset((d), 0, sizeof(d));
  tv = 0;
  tt = 1;
  d[tt][0] = 1;
  for (int i = (0); i < (int)(n); ++i) {
    swap(tv, tt);
    memset((d[tt]), 0, sizeof(d[tt]));
    for (int j = (0); j <= (int)(goal); ++j) {
      if (d[tv][j]) {
        d[tt][j] = 1;
        d[tt][j + a[i]] = 1;
      }
    }
  }
  return d[tt][goal];
}
vector<int> a[5005];
int second[5005];
int n, p[5005], b[11], sub_tree[11], to[5005];
void dfs0(int v) {
  if (a[v].size() == 0)
    second[v] = 1;
  else
    second[v] = 0;
  for (int i = (0); i < (int)(a[v].size()); ++i) {
    dfs0(a[v][i]);
    second[v] += second[a[v][i]];
  }
  for (int i = (0); i <= (int)(3); ++i) {
    if (b[i] == v) {
      int u = v;
      while (u != 1) {
        to[u] = 1;
        if (p[u] == 1) {
          sub_tree[i] = u;
        }
        u = p[u];
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> b[0] >> b[1] >> b[2] >> b[3];
  p[1] = 0;
  for (int i = (2); i <= (int)(n); ++i) {
    cin >> p[i];
    a[p[i]].push_back(i);
  }
  memset((to), 0, sizeof(to));
  dfs0(1);
  if (second[1] % 2 == 1) {
    cout << "NO"
         << "\n";
    return 0;
  }
  int goal[2];
  vector<int> r[2];
  goal[0] = second[1] / 2 - 1 - second[sub_tree[2]];
  goal[1] = second[1] / 2 - 1 - second[sub_tree[1]];
  for (int i = (0); i < (int)(a[1].size()); ++i) {
    if (!to[a[1][i]]) {
      r[0].push_back(second[a[1][i]]);
      r[1].push_back(second[a[1][i]]);
    }
  }
  int v, last;
  last = b[0];
  v = p[b[0]];
  while (v != 1) {
    for (int i = (0); i < (int)(a[v].size()); ++i) {
      if (a[v][i] != last) {
        r[0].push_back(second[a[v][i]]);
      }
    }
    v = p[v];
  }
  last = b[1];
  v = p[b[1]];
  while (v != 1) {
    for (int i = (0); i < (int)(a[v].size()); ++i) {
      if (a[v][i] != last) {
        r[0].push_back(second[a[v][i]]);
      }
    }
    v = p[v];
  }
  last = b[2];
  v = p[b[2]];
  while (v != 1) {
    for (int i = (0); i < (int)(a[v].size()); ++i) {
      if (a[v][i] != last) {
        r[1].push_back(second[a[v][i]]);
      }
    }
    v = p[v];
  }
  last = b[3];
  v = p[b[3]];
  while (v != 1) {
    for (int i = (0); i < (int)(a[v].size()); ++i) {
      if (a[v][i] != last) {
        r[1].push_back(second[a[v][i]]);
      }
    }
    v = p[v];
  }
  if (rucksack(r[0], goal[0]) && rucksack(r[1], goal[1]))
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
  return 0;
}
