#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 3e5 + 7;
struct edge {
  long long to, far, nxt;
} e[df << 1];
edge ee[df << 1];
long long i, j, k, l, m, n, o = 1, p, q, r, s, t, u, v, w, x, y, z, head[df];
long long top, sta[df], vis[df], cnt, tot, dfn[df], low[df], col[df], val[df],
    cur[df], num[df];
inline void add(long long u, long long v, long long w) {
  return e[++o] = (edge){v, w, head[u]}, head[u] = o, void();
}
inline void adde(long long u, long long v, long long w) {
  return ee[++o] = (edge){v, w, cur[u]}, cur[u] = o, void();
}
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
void tarjan(long long u, long long lst) {
  vis[u] = 1;
  sta[++top] = u, low[u] = dfn[u] = ++tot;
  for (long long i = head[u], v; i; i = e[i].nxt) {
    v = e[i].to;
    if (v == lst) continue;
    if (!dfn[v]) {
      tarjan(v, u), low[u] = min(low[u], low[v]);
    } else if (vis[v])
      low[u] = min(low[u], low[v]);
  }
  if (low[u] == dfn[u]) {
    col[u] = ++cnt;
    while (sta[top] != u) {
      col[sta[top]] = cnt;
      vis[sta[top]] = 0;
      top--;
    }
    top--;
    vis[u] = 0;
  }
  return;
}
void dfs(long long u, long long lst) {
  num[u] |= val[u];
  if (u == col[y] && num[u] == 1) {
    k = 1;
    return;
  }
  for (long long i = head[u], v; i; i = e[i].nxt) {
    v = e[i].to;
    if (v == lst || num[v] != 0) continue;
    num[v] = num[u] | e[i].far, dfs(v, u);
  }
}
int main() {
  n = read(), m = read();
  for (long long i = (1); i <= (m); ++i) {
    long long u = read(), v = read(), w = read();
    add(u, v, w), add(v, u, w);
  }
  tarjan(1, 0);
  for (long long u = (1); u <= (n); ++u) {
    for (long long i = head[u], v; i; i = e[i].nxt) {
      v = e[i].to;
      if (col[v] != col[u] || u >= v) continue;
      val[col[u]] |= e[i].far;
    }
  }
  o = 1;
  for (long long u = (1); u <= (n); ++u) {
    for (long long i = head[u], v; i; i = e[i].nxt) {
      v = e[i].to;
      if (col[v] == col[u] || u >= v) continue;
      adde(col[u], col[v], e[i].far), adde(col[v], col[u], e[i].far);
    }
  }
  memcpy(head, cur, sizeof(cur));
  memcpy(e, ee, sizeof(ee));
  x = read(), y = read(), dfs(col[x], 0);
  if (k)
    puts("YES");
  else
    puts("NO");
  return 0;
}
