#include <bits/stdc++.h>
using namespace std;
struct Road {
  int e, next, tag, used;
} r[620000], r1[1300000];
int R[310000], R1[310000];
int low[310000], dfn[310000], ins[310000], sta[310000], bl[310000];
int have[310000], S, T, n, m, _, num = 1, num1 = 1, top, piece, Index, ans;
void clear() {
  num = num1 = 1;
  top = piece = ans = 0;
  memset(R, 0, sizeof(R));
  memset(R1, 0, sizeof(R1));
  memset(low, 0, sizeof(low));
  memset(dfn, 0, sizeof(dfn));
  memset(ins, 0, sizeof(ins));
  memset(sta, 0, sizeof(sta));
  memset(bl, 0, sizeof(bl));
  memset(have, 0, sizeof(have));
}
void addr1(int x, int y, int tag) {
  ++num1;
  r1[num1].e = y;
  r1[num1].tag = tag;
  r1[num1].next = R1[x];
  r1[num1].used = 0;
  R1[x] = num1;
}
void addr(int x, int y, int tag) {
  ++num;
  r[num].e = y;
  r[num].tag = tag;
  r[num].next = R[x];
  r[num].used = 0;
  R[x] = num;
}
void tarjan(int u) {
  low[u] = dfn[u] = ++Index;
  sta[++top] = u;
  ins[u] = 1;
  for (int i = R[u]; i; i = r[i].next) {
    if (r[i].used) continue;
    r[i].used = r[i ^ 1].used = 1;
    int v = r[i].e;
    if (dfn[v] == 0) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (ins[v] == 1) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (low[u] == dfn[u]) {
    int now = -1;
    piece++;
    while (u != now) {
      now = sta[top--];
      ins[now] = 0;
      bl[now] = piece;
    }
  }
}
void dfs(int now, int fa, int take) {
  take |= have[now];
  if (now == bl[T]) ans |= take;
  for (int i = R1[now]; i; i = r1[i].next) {
    int v = r1[i].e;
    if (v == fa) continue;
    dfs(v, now, take | r1[i].tag);
  }
}
int main() {
  int x, y, t;
  _ = 1;
  while (_--) {
    clear();
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++) {
      scanf("%d %d %d", &x, &y, &t);
      addr(x, y, t);
      addr(y, x, t);
    }
    for (int i = 1; i <= n; i++) {
      if (dfn[i] == 0) tarjan(i);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = R[i]; j; j = r[j].next) {
        int u = i, v = r[j].e;
        if (bl[u] == bl[v] && r[j].tag)
          have[bl[u]] = 1;
        else if (bl[u] != bl[v])
          addr1(bl[u], bl[v], r[j].tag);
      }
    }
    scanf("%d %d", &S, &T);
    dfs(bl[S], 0, 0);
    printf("%s\n", ans ? "YES" : "NO");
  }
  return 0;
}
