#include <bits/stdc++.h>
using namespace std;
struct Graph {
  vector<vector<int> > conn;
  vector<int> weight, p;
  int n, offcnt;
  Graph(int nsize) {
    n = nsize;
    conn.resize(n);
    weight.resize(n, 0);
    p.resize(n, -1);
    offcnt = 0;
  }
  void addEdge(int u, int v) {
    conn[u].push_back(v);
    p[v] = u;
  }
  void initWeights(int pos = 0) {
    if (conn[pos].size() == 0) {
      weight[pos] = 1;
      offcnt++;
    }
    for (auto next : conn[pos]) {
      initWeights(next);
      weight[pos] += weight[next];
    }
  }
  vector<bool> marked;
  array<int, 4> assess(array<int, 4> V) {
    marked.resize(n, false);
    array<int, 4> result = {0};
    for (int i = 0; i < 4; i++) {
      int v = V[i];
      while (v != 0) {
        marked[v] = true;
        result[i] = weight[v];
        v = p[v];
      }
    }
    return result;
  }
  bool valid(int u, int v, int toAdd) {
    int inilen = toAdd;
    vector<int> toTry;
    while (u != 0) {
      for (auto next : conn[u])
        if (!marked[next]) toTry.push_back(weight[next]);
      u = p[u];
    }
    while (v != 0) {
      for (auto next : conn[v])
        if (!marked[next]) toTry.push_back(weight[next]);
      v = p[v];
    }
    for (auto next : conn[0])
      if (!marked[next]) toTry.push_back(weight[next]);
    if (offcnt % 2 == 1) return false;
    if (inilen >= offcnt / 2) return false;
    vector<bool> canReach(offcnt / 2, false);
    canReach[inilen] = true;
    for (auto c : toTry)
      for (int i = offcnt / 2 - 1 - c; i >= 0; i--)
        if (canReach[i]) canReach[i + c] = true;
    return canReach[offcnt / 2 - 1];
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int a, b, c, d;
  cin >> n;
  cin >> a >> b >> c >> d;
  a--, b--, c--, d--;
  Graph g(n);
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    g.addEdge(p - 1, i);
  }
  g.initWeights();
  auto ret = g.assess({a, b, c, d});
  if (g.valid(a, b, ret[2]) && g.valid(c, d, ret[0]))
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
