#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline string get() {
  char ch[1001000];
  scanf("%s", ch);
  return ch;
}
template <class P, class Q>
inline P smin(P &a, Q b) {
  if (b < a) a = b;
  return a;
}
template <class P, class Q>
inline P smax(P &a, Q b) {
  if (a < b) a = b;
  return a;
}
const long long maxn = 3e5 + 10;
const long long base = 29;
const long long MAX_LG = 21;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const long long maxq = 2e5 + 10;
vector<pair<long long, long long> > g[maxn];
bool mark[maxn];
long long h[maxn], l[maxn];
long long pr[maxn];
long long good[maxn];
inline void dfs(long long v, long long par = 0, long long fl = 0) {
  if (!par) par = v;
  l[v] = h[v];
  pr[v] = par;
  mark[v] = true;
  good[v] = fl;
  for (long long i = 0; i < g[v].size(); i++) {
    long long u = g[v][i].first;
    if (!mark[u]) {
      h[u] = h[v] + 1;
      dfs(u, v, fl || g[v][i].second);
      l[v] = min(l[v], l[u]);
      if (l[u] <= h[v] && good[u]) good[v] = true;
    } else if (u != par) {
      l[v] = min(l[v], l[u]);
      if (l[u] <= h[v]) good[v] |= (good[u] || g[v][i].second);
    }
  }
}
int32_t main() {
  long long n = in(), m = in();
  for (long long i = 0; i < m; i++) {
    long long v = in(), u = in(), tp = in();
    g[v].push_back({u, tp}), g[u].push_back({v, tp});
  }
  long long source = in(), sink = in();
  long long res = 0;
  dfs(source);
  do {
    res |= good[sink];
    sink = pr[sink];
  } while (pr[sink] != sink);
  if (res)
    cout << "YES\n";
  else
    cout << "NO\n";
}
