#include <bits/stdc++.h>
using namespace std;
int n, m, f[300005], v[600005], o[600005], w[600005], d[300005], l[300005], t,
    g, in[300005], S, T, p;
bool b[600005], u[300005], h[300005];
void bd(int a, int b, int c) {
  v[++p] = b;
  o[p] = f[a];
  f[a] = p;
  w[p] = c;
}
void dfs(int x, int y) {
  d[x] = l[x] = ++t;
  for (int i = (f[x]); i; i = o[i])
    if (i != (y ^ 1)) {
      if (!d[v[i]]) {
        dfs(v[i], i);
        if (l[v[i]] > d[x]) b[i] = b[i ^ 1] = 1;
        l[x] = min(l[x], l[v[i]]);
      } else
        l[x] = min(l[x], d[v[i]]);
    }
}
void dfs2(int x, int y) {
  in[x] = y;
  for (int i = (f[x]); i; i = o[i])
    if (!b[i]) {
      if (w[i]) h[y] = 1;
      if (!in[v[i]]) dfs2(v[i], y);
    }
}
bool dfs3(int x, int y) {
  u[x] = 1;
  if (h[in[x]]) y = 1;
  if (x == T) return y;
  for (int i = (f[x]); i; i = o[i])
    if (!u[v[i]] && dfs3(v[i], w[i] ? 1 : y)) return 1;
  return 0;
}
int main() {
  p = 1;
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (m); i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    bd(a, b, c);
    bd(b, a, c);
  }
  scanf("%d %d", &S, &T);
  dfs(1, 0);
  for (int i = (1); i <= (n); i++)
    if (!in[i]) dfs2(i, ++g);
  puts(dfs3(S, 0) ? "YES" : "NO");
}
