#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d, ans, par[5020], leaves[5020];
bool iAn[5020];
vector<vector<int> > gr;
bitset<5020> dp[2];
int dfs(int x) {
  if (gr[x].size() == 0) {
    leaves[x] = 1;
  }
  for (auto i : gr[x]) {
    if (i == par[x]) {
      continue;
    }
    leaves[x] += dfs(i);
  }
  return leaves[x];
}
int setImportant(int x) {
  while (par[x] != 1) {
    iAn[x] = 1;
    x = par[x];
  }
  iAn[x] = 1;
  iAn[1] = 1;
  return x;
}
void addImportant(int x, int idx) {
  int prev = x;
  x = par[x];
  while (x != 1) {
    for (auto i : gr[x]) {
      if (i != prev) {
        dp[idx] |= dp[idx] << leaves[i];
      }
    }
    prev = x;
    x = par[x];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> a >> b >> c >> d;
  gr.resize(n + 1, vector<int>());
  for (int i = 2; i <= n; ++i) {
    int v;
    cin >> v;
    par[i] = v;
    gr[v].push_back(i);
  }
  par[1] = 1;
  dfs(1);
  setImportant(a);
  int bA = setImportant(b);
  int cA = setImportant(c);
  setImportant(d);
  if (leaves[1] % 2) {
    cout << "NO";
    return 0;
  }
  if ((leaves[1] - 2) / 2 < leaves[cA]) {
    cout << "NO";
    return 0;
  }
  if ((leaves[1] - 2) / 2 < leaves[bA]) {
    cout << "NO";
    return 0;
  }
  dp[0][0] = 1;
  for (auto x : gr[1]) {
    if (!iAn[x]) {
      dp[0] |= dp[0] << leaves[x];
    }
  }
  dp[1] = dp[0];
  addImportant(a, 0);
  addImportant(b, 0);
  addImportant(c, 1);
  addImportant(d, 1);
  if (dp[0][(leaves[1] - 2) / 2 - leaves[cA]] and
      dp[1][(leaves[1] - 2) / 2 - leaves[bA]]) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}
