#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int n;
int a, b, c, d;
vector<int> E[maxn];
bool ablink[maxn];
bool cdlink[maxn];
vector<int> ab;
vector<int> cd;
void addEdge(int u, int v) {
  E[u].push_back(v);
  E[v].push_back(u);
}
bool dfs(int u, int pre, int target) {
  if (u == target) {
    if (target == b) {
      ablink[u] = 1;
    }
    if (target == d) {
      cdlink[u] = 1;
    }
    return 1;
  }
  int sz = E[u].size();
  for (int i = 0; i < sz; i++) {
    int v = E[u][i];
    if (v == pre) continue;
    if (dfs(v, u, target)) {
      if (target == b) {
        ablink[u] = 1;
      }
      if (target == d) {
        cdlink[u] = 1;
      }
      return 1;
    }
  }
  return 0;
}
int dfsab(int u, int pre) {
  int sz = E[u].size();
  int re = (sz == 1 && u != 1);
  for (int i = 0; i < sz; i++) {
    int v = E[u][i];
    if (v == pre) continue;
    int tmp = dfsab(v, u);
    re += tmp;
    if (ablink[u] && !ablink[v]) {
      ab.push_back(tmp);
    }
  }
  return re;
}
int dfscd(int u, int pre) {
  int sz = E[u].size();
  int re = (sz == 1 && u != 1);
  for (int i = 0; i < sz; i++) {
    int v = E[u][i];
    if (v == pre) continue;
    int tmp = dfscd(v, u);
    re += tmp;
    if (cdlink[u] && !cdlink[v]) {
      cd.push_back(tmp);
    }
  }
  return re;
}
bool dpab[2][maxn * 2];
bool dpcd[2][maxn * 2];
int main() {
  cin >> n;
  cin >> a >> b >> c >> d;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    addEdge(i, p);
  }
  dfs(a, 0, b);
  dfs(c, 0, d);
  dfsab(a, 0);
  dfscd(c, 0);
  bool ok = 1;
  int cur = 0;
  int pre = 1;
  dpab[cur][n] = 1;
  for (int x : ab) {
    swap(cur, pre);
    memset(dpab[cur], 0, sizeof(dpab[cur]));
    for (int i = 0; i < n * 2; i++) {
      if (dpab[pre][i]) {
        dpab[cur][i - x] = 1;
        dpab[cur][i + x] = 1;
      }
    }
  }
  ok &= dpab[cur][n];
  dpcd[cur][n] = 1;
  for (int x : cd) {
    swap(cur, pre);
    memset(dpcd[cur], 0, sizeof(dpcd[cur]));
    for (int i = 0; i < n * 2; i++) {
      if (dpcd[pre][i]) {
        dpcd[cur][i - x] = 1;
        dpcd[cur][i + x] = 1;
      }
    }
  }
  ok &= dpcd[cur][n];
  if (ok) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}
