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

//Problem "Path from S to T"
//10th Internet Olympiad, basic level, season 2007-2008.
//Problem Author: Fedor Tsarev, tsarev@rain.ifmo.ru
//Solution Author: Maxim Buzdalov, buzdalov@rain.ifmo.ru

//O(N^3 + M) solution.

public class path_mb_slow {
    public static void main(String[] args) throws IOException {
	BufferedReader in = new BufferedReader(new FileReader("path.in"));
	StringTokenizer st0 = new StringTokenizer(in.readLine());
	int n = Integer.parseInt(st0.nextToken());
	int m = Integer.parseInt(st0.nextToken());
	int maxw = Integer.parseInt(in.readLine());
	
	BitSet[] next = new BitSet[n];
	for (int i = 0; i < n; ++i) {
	    next[i] = new BitSet(n);
	}
	for (int i = 0; i < m; ++i) {
	    StringTokenizer st1 = new StringTokenizer(in.readLine());
	    int s = Integer.parseInt(st1.nextToken()) - 1;
	    int f = Integer.parseInt(st1.nextToken()) - 1;
	    int w = Integer.parseInt(st1.nextToken());
	    if (w >= maxw) {
		next[s].set(f);
		next[f].set(s);
	    }
	}
	in.close();
	
	for (int k = 0; k < n; ++k) {
	    for (int i = 0; i < n; ++i) {
		if (next[i].get(k)) {
		    next[i].or(next[k]);
		}
	    }    
	}
	
	PrintWriter out = new PrintWriter("path.out");
	out.println(next[0].get(n - 1) ? "YES" : "NO");
	out.close();
    }
}
