#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, oo = inf;
inline long long read() {
  register long long x = 0;
  char f = 0;
  register char c = getchar();
  for (; !isdigit(c); c = getchar()) f |= (c == '-');
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return f ? -x : x;
}
inline double readdb() {
  register double x = 0, p = 0.1;
  register char f = 0, c = getchar();
  for (; !isdigit(c); c = getchar()) f |= (c == '-');
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  if (c == '.')
    for (c = getchar(); isdigit(c); c = getchar(), p /= 10)
      x = x + (c ^ 48) * p;
  return f ? -x : x;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void writeln(long long x, char c, long long y) {
  write(x);
  putchar(c);
  writeln(y);
}
inline void writeln(long long x, char c, long long y, char d, long long z) {
  write(x);
  putchar(c);
  write(y);
  putchar(d);
  writeln(z);
}
const int maxn = 3e5 + 233;
const int maxm = 6e5 + 233;
struct Edge {
  int to, nxt, dist;
  Edge() {}
  Edge(int to, int nxt, int dist) : to(to), nxt(nxt), dist(dist) {}
} edge1[maxm], edge2[maxm];
int first1[maxn], first2[maxn];
int nume1, nume2;
void Addedge1(int a, int b, int c) {
  edge1[nume1] = Edge(b, first1[a], c);
  first1[a] = nume1++;
}
int s[maxn], dfn[maxn], low[maxn], dfsclk = 0;
bool Ins[maxn];
int bel[maxn];
int val[maxn], dist[maxn];
void Tarjan(int u, int fa) {
  dfn[u] = low[u] = ++dfsclk;
  Ins[u] = true;
  s[++*s] = u;
  for (int e = first1[u]; ~e; e = edge1[e].nxt) {
    int v = edge1[e].to;
    if (v == fa) continue;
    if (!dfn[v]) {
      Tarjan(v, u);
      low[u] = min(low[u], low[v]);
    } else if (Ins[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (dfn[u] == low[u]) {
    bel[0]++;
    for (;;) {
      int v = s[s[0]--];
      Ins[v] = false;
      bel[v] = *bel;
      if (u == v) break;
    }
  }
}
void Addedge2(int a, int b, int c) {
  edge2[nume2] = Edge(b, first2[a], c);
  first2[a] = nume2++;
}
void rebuild() {
  memset(val, false, sizeof(val));
  for (int i = 0; i < nume1; i += 2) {
    int u = bel[edge1[i ^ 1].to];
    int v = bel[edge1[i].to];
    int w = edge1[i].dist;
    if (u != v) {
      Addedge2(u, v, w);
      Addedge2(v, u, w);
    } else if (w) {
      val[u] = true;
    }
  }
}
int front, rear, q[maxn];
void BFS(int S, int T) {
  memset(dist, -1, sizeof(dist));
  front = rear = 0;
  q[rear++] = S;
  dist[S] = val[S];
  while (front < rear) {
    int u = q[front++];
    for (int e = first2[u]; ~e; e = edge2[e].nxt) {
      int v = edge2[e].to;
      if (dist[v] == -1) {
        dist[v] = dist[u] | edge2[e].dist | val[v];
        q[rear++] = v;
      }
    }
  }
  if (dist[T]) {
    puts("YES");
  } else {
    puts("NO");
  }
}
int n, m;
int main() {
  n = read(), m = read();
  memset(first1, -1, sizeof(first1));
  nume1 = 0;
  memset(first2, -1, sizeof(first2));
  nume2 = 0;
  for (register int i = (1); i <= (m); ++i) {
    int a = read(), b = read(), c = read();
    Addedge1(a, b, c);
    Addedge1(b, a, c);
  }
  memset(dfn, 0, sizeof(dfn));
  *bel = 0;
  Tarjan(1, 0);
  rebuild();
  int s = read(), t = read();
  BFS(bel[s], bel[t]);
  return 0;
}
