#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
  return x * f;
}
const int N = 3e5 + 5;
struct edge {
  int y, v, next;
} e[N << 1];
int cnt = 1, first[N];
inline void add(int x, int y, int v) {
  e[++cnt] = {y, v, first[x]};
  first[x] = cnt;
}
struct Edge {
  int y, v, next;
} E[N << 1];
int Cnt = 1, head[N];
inline void Add(int x, int y, int v) {
  E[++Cnt] = {y, v, head[x]};
  head[x] = Cnt;
}
int dfn[N], low[N], tim, bel[N], B, st[N], top, ins[N];
void tarjan(int x, int fa) {
  ins[st[++top] = x] = 1;
  dfn[x] = low[x] = ++tim;
  for (int i = first[x]; i; i = e[i].next) {
    int y = e[i].y;
    if (y == fa) continue;
    if (!dfn[y])
      tarjan(y, x), low[x] = min(low[x], low[y]);
    else if (ins[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] == low[x]) {
    int z;
    B++;
    do {
      ins[z = st[top--]] = 0;
      bel[z] = B;
    } while (z ^ x);
  }
}
int vis[N];
int a, b, Flag;
void dfs(int x, int fa, int flag) {
  if (vis[x]) flag = 1;
  if (x == bel[b]) {
    Flag = flag;
    return;
  }
  for (int i = head[x]; i; i = E[i].next) {
    int y = E[i].y, v = E[i].v;
    if (y == fa) continue;
    dfs(y, x, flag | v);
  }
}
int n, m;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), v = read();
    add(x, y, v);
    add(y, x, v);
  }
  tarjan(1, 0);
  for (int i = 2; i <= cnt; i += 2) {
    int x = e[i].y, y = e[i ^ 1].y;
    if (bel[x] == bel[y] && e[i].v)
      vis[bel[x]] = 1;
    else if (bel[x] != bel[y])
      Add(bel[x], bel[y], e[i].v), Add(bel[y], bel[x], e[i].v);
  }
  a = read(), b = read();
  dfs(bel[a], 0, 0);
  if (Flag)
    puts("YES");
  else
    puts("NO");
  return 0;
}
