#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, num = 0, c = 1;
int head[300010], deep[300010], val[300010], path[300010];
struct Edge {
  int next, to, w;
} a[300010 << 1];
char tp[100000], *p1 = tp, *p2 = tp;
inline char get_char() {
  return p1 == p2 && (p2 = (p1 = tp) + fread(tp, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int date = 0, w = 1;
  char c = 0;
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = get_char();
  }
  while (c >= '0' && c <= '9') {
    date = date * 10 + c - '0';
    c = get_char();
  }
  return date * w;
}
namespace Kruskal {
int d = 0;
int fa[300010], size[300010], son[300010], top[300010];
struct Graph {
  int u, v, w;
  friend bool operator<(const Graph &u, const Graph &v) { return u.w > v.w; }
} graph[300010];
inline void add(int u, int v, int w) {
  d++;
  graph[d].u = u;
  graph[d].v = v;
  graph[d].w = w;
}
inline void add_edge(int u, int v, int w) {
  a[c].to = v;
  a[c].w = w;
  a[c].next = head[u];
  head[u] = c++;
  a[c].to = u;
  a[c].w = w;
  a[c].next = head[v];
  head[v] = c++;
}
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void uniun(int x, int y) {
  x = find(x);
  y = find(y);
  if (x != y) fa[y] = x;
}
bool check(int x, int y) {
  x = find(x);
  y = find(y);
  return x == y;
}
void kruskal() {
  sort(graph + 1, graph + d + 1);
  for (int i = 1; i <= num; i++) fa[i] = i;
  for (int i = 1; i <= d; i++)
    if (!check(graph[i].u, graph[i].v)) {
      add_edge(graph[i].u, graph[i].v, graph[i].w);
      uniun(graph[i].u, graph[i].v);
    }
  for (int i = 1; i <= num; i++) fa[i] = 0;
}
void dfs1(int rt) {
  size[rt] = 1;
  son[rt] = 0;
  for (int i = head[rt]; i; i = a[i].next) {
    int will = a[i].to;
    if (!deep[will]) {
      deep[will] = deep[rt] + 1;
      fa[will] = rt;
      val[will] += val[rt];
      path[will] = path[rt] + a[i].w;
      dfs1(will);
      size[rt] += size[will];
      if (size[son[rt]] < size[will]) son[rt] = will;
    }
  }
}
void dfs2(int rt, int f) {
  top[rt] = f;
  if (son[rt]) dfs2(son[rt], f);
  for (int i = head[rt]; i; i = a[i].next) {
    int will = a[i].to;
    if (will != fa[rt] && will != son[rt]) dfs2(will, will);
  }
}
int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (deep[top[x]] < deep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  if (deep[x] > deep[y]) swap(x, y);
  return x;
}
void solve() {
  int lca = LCA(s, t);
  if (path[s] + path[t] - 2 * path[lca] + val[s] + val[t] - val[lca] -
          val[fa[lca]] >=
      1)
    printf("YES\n");
  else
    printf("NO\n");
}
void work() {
  kruskal();
  deep[1] = 1;
  dfs1(1);
  dfs2(1, 1);
  solve();
}
}  // namespace Kruskal
namespace Tarjan {
int d = 1;
int low[300010], colour[300010];
int top = 0, stack[300010];
struct Graph {
  int u, v, w;
} graph[300010];
inline void add_edge(int u, int v, int w) {
  a[c].to = v;
  a[c].w = w;
  a[c].next = head[u];
  head[u] = c++;
  a[c].to = u;
  a[c].w = w;
  a[c].next = head[v];
  head[v] = c++;
}
void tarjan(int x, int fa) {
  deep[x] = low[x] = d++;
  stack[++top] = x;
  for (int i = head[x]; i; i = a[i].next) {
    int v = a[i].to;
    if (v == fa) continue;
    if (!deep[v]) {
      tarjan(v, x);
      low[x] = min(low[x], low[v]);
    } else {
      low[x] = min(low[x], deep[v]);
    }
  }
  if (low[x] == deep[x]) {
    num++;
    do {
      colour[stack[top]] = num;
    } while (stack[top--] != x);
  }
}
void build_new_graph() {
  c = 1;
  memset(head, 0, sizeof(head));
  memset(val, 0, sizeof(val));
  memset(path, 0, sizeof(path));
  memset(deep, 0, sizeof(deep));
  memset(a, 0, sizeof(a));
  s = colour[s];
  t = colour[t];
  for (int i = 1; i <= m; i++) {
    if (colour[graph[i].u] != colour[graph[i].v])
      Kruskal::add(colour[graph[i].u], colour[graph[i].v], graph[i].w);
    else
      val[colour[graph[i].u]] |= graph[i].w;
  }
}
void work() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    graph[i].u = read();
    graph[i].v = read();
    graph[i].w = read();
    add_edge(graph[i].u, graph[i].v, graph[i].w);
  }
  s = read();
  t = read();
  for (int i = 1; i <= n; i++)
    if (!deep[i]) tarjan(i, 0);
  build_new_graph();
}
}  // namespace Tarjan
int main() {
  Tarjan::work();
  Kruskal::work();
  return 0;
}
