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

public class path_mb implements Runnable {
    int[] p, r;
    
    int get(int x) {
	return p[x] == x ? x : (p[x] = get(p[x]));
    }
    
    void unite(int a, int b) {
	a = get(a);
	b = get(b);
	if (a != b) {
	    if (r[a] <= r[b]) {
		p[a] = b;
	    } else {
		p[b] = a;
	    }
	    if (r[a] == r[b]) {
		r[b]++;
	    }
	}
    }
    
    public void run() {
	try {
	    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 w = Integer.parseInt(in.readLine());
	    p = new int[n];
	    r = new int[n];
	    for (int i = 0; i < n; ++i) {
		p[i] = i;
	    }
	    for (int i = 0; i < m; ++i) {
		StringTokenizer st = new StringTokenizer(in.readLine());
		int s = Integer.parseInt(st.nextToken()) - 1;
		int f = Integer.parseInt(st.nextToken()) - 1;
		int ww = Integer.parseInt(st.nextToken());
		if (ww >= w) {
		    unite(s, f);
		}
	    }
	    in.close();
	    PrintWriter out = new PrintWriter("path.out");
	    out.println(get(0) == get(n - 1) ? "YES" : "NO");
	    out.close();
	} catch (IOException e) {
	    throw new RuntimeException(e);
	}
    }
    
    public static void main(String[] args) {
	new Thread(new path_mb()).start();
    }
}