#include <bits/stdc++.h>
int read() {
  char k = getchar();
  int x = 0;
  while (k < '0' || k > '9') k = getchar();
  while (k >= '0' && k <= '9') x = x * 10 + k - '0', k = getchar();
  return x;
}
const int MX = 3e5 + 233;
int n, m;
int ORG[MX], NEW[MX], tot = 1;
struct edge {
  int node, next, w;
} h[MX << 3];
void addedge(int u, int v, int w, int *head, int flg = 1) {
  h[++tot] = (edge){v, head[u], w}, head[u] = tot;
  if (flg) addedge(v, u, w, head, false);
}
int DFN[MX], low[MX], cnt, stk[MX], top;
int col[MX], haveone[MX];
void tarjan(int x, int las, int *head = ORG) {
  DFN[x] = low[x] = ++cnt, stk[++top] = x;
  for (int i = head[x], d; i; i = h[i].next) {
    if (i == (las ^ 1)) continue;
    if (!DFN[d = h[i].node]) {
      tarjan(d, i);
      low[x] = std::min(low[x], low[d]);
    } else if (DFN[d] < low[x])
      low[x] = DFN[d];
  }
  if (low[x] == DFN[x]) {
    int j = 0;
    while (j != x) {
      j = stk[top--];
      col[j] = x;
    }
  }
}
void rebuild(int *head, int *nhead) {
  for (int x = 1; x <= n; ++x) {
    for (int i = head[x], d; i; i = h[i].next) {
      if (col[d = h[i].node] == col[x]) {
        if (h[i].w) haveone[col[x]] = 1;
      }
    }
  }
  for (int x = 1; x <= n; ++x) {
    for (int i = head[x], d; i; i = h[i].next) {
      if (col[d = h[i].node] == col[x]) {
        continue;
      }
      int w = h[i].w || haveone[col[d]] || haveone[col[x]];
      addedge(col[x], col[d], w, nhead);
    }
  }
}
int A, B;
bool check(int x, int ok = 0, int *head = NEW) {
  ok |= haveone[x];
  DFN[x] = 1;
  if (x == B) {
    if (ok)
      puts("YES");
    else
      puts("NO");
    return 1;
  }
  for (int i = head[x], d; i; i = h[i].next) {
    if (DFN[d = h[i].node]) continue;
    if (check(d, ok | h[i].w)) return 1;
  }
  return 0;
}
int main() {
  n = read(), m = read();
  for (int i = 1, u, v, w; i <= m; ++i) {
    u = read(), v = read(), w = read();
    addedge(u, v, w, ORG);
  }
  tarjan(1, 0);
  rebuild(ORG, NEW);
  A = col[read()], B = col[read()];
  memset(DFN, 0, sizeof DFN);
  check(A);
  return 0;
}
