import sys import heapq input = sys.stdin.readline class UnionFind: def __init__(self, n, w): self.par = [-1] * n self.rank = [0] * n self.siz = [1] * n self.weight = [[] for _ in range(n)] self.cnt = n for i in range(n): for p in w[i]: heapq.heappush(self.weight[i], p) def root(self, x): if self.par[x] == -1: return x self.par[x] = self.root(self.par[x]) return self.par[x] def unite(self, x, y): px = self.root(x) py = self.root(y) if px == py: return False if self.rank[px] < self.rank[py]: px, py = py, px self.par[py] = px if self.rank[px] == self.rank[py]: self.rank[px] += 1 self.siz[px] += self.siz[py] self.cnt -= 1 if len(self.weight[px]) < len(self.weight[py]): self.weight[px], self.weight[py] = self.weight[py], self.weight[px] while self.weight[py]: g = heapq.heappop(self.weight[py]) if self.root(g[1]) == px: continue heapq.heappush(self.weight[px], g) return True def count(self): return self.cnt def size(self, x): return self.siz[self.root(x)] def getweight(self, x): return self.weight[self.root(x)] N, M, K = map(int, input().split()) A = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 G[u].append((A[v], v)) G[v].append((A[u], u)) UF = UnionFind(N, G) dp = [(A[i], i) for i in range(N)] heapq.heapify(dp) while UF.count() > 1: if not dp: break a, i = heapq.heappop(dp) ri = UF.root(i) heap = UF.getweight(i) while heap: s, j = heapq.heappop(heap) rj = UF.root(j) if ri == rj: continue if s - a > K: print("No") sys.exit() UF.unite(i, j) break print("Yes")