// Задача "Путь из S в T"
// 10-ая Интернет-олимпиада сезона 2007-2008, базовый уровень
// Автор задачи: Федор Царев, tsarev@rain.ifmo.ru
// Автор решения: Сергей Поромов, poromov@rain.ifmo.ru

import java.io.*;
import java.util.*;

public class path_sp implements Runnable {

	public static void main(String[] args) {
		new Thread(new path_sp()).run();
	}

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;

	PrintWriter out;

	StringTokenizer st;

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean e, String s) {
		if (!e) {
			throw new Error("Assertion failure " + s);
		}
	}

	private static final String FILENAME = "path";
	
	int n, M;
	int[][] w;
	boolean[] q;
	
	boolean dfs(int i) {
		if (i == n - 1) {
			return true;
		}
		q[i] = true;
		for (int j = 0; j < n; j++) {
			if (!q[j] && w[i][j] >= M && dfs(j)) {
				return true;
			}
		}
		return false;
	}

	public void solve() throws IOException {
		br = new BufferedReader(new FileReader(FILENAME + ".in"));
		out = new PrintWriter(FILENAME + ".out");
		n = nextInt();
		myAssert(n >= 2 && n <= 1000, "1");
		int m = nextInt();
		myAssert(m >= 0 && m <= 100000, "2");
		M = nextInt();
		myAssert(M >= 1 && M <= 10e9, "3");
		w = new int[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(w[i], -1);
		}
		q = new boolean[n];
		for (int i = 0; i < m; i++) {
			int u = nextInt() - 1;
			int v = nextInt() - 1;
			myAssert(u >= 0 && u < n, "4");
			myAssert(v >= 0 && v < n, "5");
			myAssert(w[u][v] == -1, "6");
			w[u][v] = nextInt();
			myAssert(w[u][v] >= 1 && w[u][v] <= 1e9, "7");
			w[v][u] = w[u][v];
		}
		if (dfs(0)) {
			out.println("YES");
		} else {
			out.println("NO");
		}
		out.close();
	}
}
