#include <bits/stdc++.h>
using namespace std;
const int maxn = 666666;
int tot, TOT, fir[maxn], nxt[maxn], to[maxn], Nxt[maxn], Fir[maxn], To[maxn],
    D[maxn], blo[maxn], stk[maxn], low[maxn], tp;
bool vis[maxn], col[maxn], dis[maxn];
struct hhh {
  int a, b, c;
  hhh() {}
  hhh(int x, int y, int z) { a = x, b = y, c = z; }
} h[maxn];
void add_edge(int x, int y) { nxt[++tot] = fir[x], to[fir[x] = tot] = y; }
void tarjan(int x, int y) {
  int dfn = low[x] = ++tot;
  stk[++tp] = x;
  for (int i = fir[x], v = to[i]; i; i = nxt[i], v = to[i])
    if (v != y) {
      if (!low[v]) tarjan(v, x);
      low[x] = min(low[x], low[v]);
    }
  if (dfn == low[x]) {
    ++TOT;
    while (stk[tp + 1] != x) blo[stk[tp--]] = TOT;
  }
}
void Add_edge(int x, int y, int z) {
  Nxt[++TOT] = Fir[x], To[Fir[x] = TOT] = y, D[TOT] = z;
}
void bfs(int x) {
  dis[x] = col[x];
  int l = 1, r = 0;
  stk[++r] = x, vis[x] = true;
  while (l <= r) {
    int q = stk[l++];
    for (int i = Fir[q], v = To[i]; i; i = Nxt[i], v = To[i])
      if (!vis[v]) {
        vis[v] = true, stk[++r] = v, dis[v] = dis[q] | D[i] | col[v];
      }
  }
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    add_edge(a, b), add_edge(b, a);
    h[i] = hhh(a, b, c);
  }
  int ss, tt;
  scanf("%d%d", &ss, &tt);
  tarjan(1, tot = 0);
  TOT = 0;
  for (int i = 1; i <= M; ++i) {
    if (blo[h[i].a] != blo[h[i].b])
      Add_edge(blo[h[i].a], blo[h[i].b], h[i].c),
          Add_edge(blo[h[i].b], blo[h[i].a], h[i].c);
    else if (h[i].c)
      col[blo[h[i].a]] = true;
  }
  bfs(blo[ss]);
  puts(dis[blo[tt]] ? "YES" : "NO");
  return 0;
}
