output_description: If A and C can communicate, print `Yes`; if they cannot, print `No`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      a b c d
attempt: n, m = map(int, input().split())
  p = list(map(int, input().split()))
  
  
  class UnionFind:
      def __init__(self, n):
          self.n = n
          self.parents = [-1] * n
  
      def find(self, x):
          if self.parents[x] < 0:
              return x
          else:
              self.parents[x] = self.find(self.parents[x])
              return self.parents[x]
  
      def union(self, x, y):
          x = self.find(x)
          y = self.find(y)
  
          if x == y:
              return
  
          if self.parents[x] > self.parents[y]:
              x, y = y, x
  
          self.parents[x] += self.parents[y]
          self.parents[y] = x
  
      def size(self, x):
          return -self.parents[self.find(x)]
  
      def same(self, x, y):
          return self.find(x) == self.find(y)
  
      def members(self, x):
          root = self.find(x)
          return [i for i in range(self.n) if self.find(i) == root]
  
      def roots(self):
          return [i for i, x in enumerate(self.parents) if x < 0]
  
      def group_count(self):
          return len(self.roots())
  
      def all_group_members(self):
          return {r: self.members(r) for r in self.roots()}
  
      def __str__(self):
          return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
  
  
  uf = UnionFind(n)
  for i in range(m):
      x, y = map(int, input().split())
      uf.union(x - 1, y - 1)
  ans = 0
  for i in range(n):
      if uf.find(i) == uf.find(p[i] - 1):
          ans += 1
  print(ans)
  
problem_description: Statement
  
  Three people, A, B and C, are trying to communicate using transceivers. They
  are standing along a number line, and the coordinates of A, B and C are a, b
  and c (in meters), respectively. Two people can directly communicate when the
  distance between them is at most d meters. Determine if A and C can
  communicate, either directly or indirectly. Here, A and C can indirectly
  communicate when A and B can directly communicate and also B and C can
  directly communicate.
samples: [{"input": "4 7 9 3", "output": "Yes\n    \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n    \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n    \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]