#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 5005;
int p[N];
vector<int> g[N];
int sz[N];
int n;
void go(int x) {
  if (int((g[x]).size()) == 0) sz[x] = 1;
  for (auto &&y : g[x]) {
    go(y);
    sz[x] += sz[y];
  }
}
void find_par(int &x) {
  while (true) {
    if (p[x] == 1) break;
    x = p[x];
  }
}
vector<int> e;
void find_sizes(int a) {
  while (true) {
    int x = p[a];
    if (x == 1) break;
    for (auto &&y : g[x]) {
      if (y == a)
        continue;
      else
        e.emplace_back(sz[y]);
    }
    a = x;
  }
}
bool cur[N];
bool check(int a, int b, int r, int c, int d) {
  if (r < 0) return false;
  e.clear();
  int ar = a, br = b, cr = c, dr = d;
  find_par(ar);
  find_par(br);
  find_par(cr);
  find_par(dr);
  for (auto &&y : g[1]) {
    if (y == ar || y == br || y == cr || y == dr)
      continue;
    else
      e.emplace_back(sz[y]);
  }
  find_sizes(a);
  find_sizes(b);
  for (int i = (r); i >= 0; --i) cur[i] = 0;
  cur[0] = 1;
  for (auto &&y : e) {
    for (int i = (r); i >= y; --i) {
      cur[i] |= cur[i - y];
    }
  }
  return cur[r];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int m = 0;
  for (int i = 2; i <= (n); ++i) {
    cin >> p[i];
    g[p[i]].emplace_back(i);
  }
  for (int i = 1; i <= (n); ++i) {
    if (int((g[i]).size()) == 0) m++;
  }
  if (m & 1) {
    cout << "NO" << endl;
    return 0;
  }
  go(1);
  int ar = a, br = b, cr = c, dr = d;
  find_par(ar);
  find_par(br);
  find_par(cr);
  find_par(dr);
  if (check(a, b, m / 2 - 1 - sz[cr], c, d) &&
      check(c, d, m / 2 - 1 - sz[br], a, b)) {
    cout << "YES" << endl;
  } else
    cout << "NO" << endl;
  return 0;
}
