#include <bits/stdc++.h>
using namespace std;
void file(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
template <typename Tp>
void read(Tp &x) {
  x = 0;
  int fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= fh;
}
int n, m;
int c[1000005];
namespace Tree {
struct Edge {
  int f, t, w, nxt;
} edge[2000005];
int head[1000005], etot = 1;
void add_edge(int f, int t, int w) {
  edge[++etot] = (Edge){f, t, w, head[f]};
  head[f] = etot;
}
int a[1000005];
int S, T;
int fa[1000005], dis[1000005];
void dfs1(int x, int pa) {
  fa[x] = pa;
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    if (y == pa) continue;
    dis[y] = dis[x] + edge[i].w;
    dfs1(y, x);
  }
}
int ww;
void solve() {
  read(S);
  read(T);
  S = c[S];
  T = c[T];
  dfs1(S, 0);
  int x = T;
  while (x) {
    ww |= a[x];
    x = fa[x];
  }
  if (dis[T]) ww = 1;
  puts(ww ? "YES" : "NO");
}
}  // namespace Tree
namespace Tarjan {
using Tree::a;
struct Edge {
  int f, t, w, nxt;
} edge[2000005];
int head[1000005], etot = 1;
void add_edge(int f, int t, int w) {
  edge[++etot] = (Edge){f, t, w, head[f]};
  head[f] = etot;
}
int dfn[1000005], low[1000005], ins[1000005], tot, cnt;
stack<int> st;
map<pair<int, int>, int> mp;
void dfs(int x, int pa) {
  dfn[x] = low[x] = ++tot;
  st.push(x);
  ins[x] = 1;
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    if (y == pa) continue;
    if (dfn[y]) {
      if (ins[y]) low[x] = min(low[x], dfn[y]);
    } else {
      dfs(y, x);
      low[x] = min(low[x], low[y]);
    }
  }
  if (dfn[x] == low[x]) {
    int y = st.top();
    st.pop();
    c[y] = ++cnt;
    ins[y] = 0;
    while (y != x) {
      y = st.top();
      st.pop();
      c[y] = cnt;
      ins[y] = 0;
    }
  }
}
void solve() {
  read(n);
  read(m);
  for (int i = 1, u, v, w; i <= m; ++i) {
    read(u);
    read(v);
    read(w);
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  for (int i = 1; i <= n; ++i) {
    if (!dfn[i]) dfs(i, 0);
  }
  for (int i = 1, u, v, w; i <= m; ++i) {
    u = edge[i << 1].f, v = edge[i << 1].t, w = edge[i << 1].w;
    if (!w) continue;
    if (c[u] == c[v]) {
      a[c[u]] = 1;
      continue;
    }
    if (c[u] > c[v]) swap(u, v);
    if (mp.count(make_pair(c[u], c[v]))) continue;
    mp[make_pair(c[u], c[v])] = 1;
    Tree::add_edge(c[u], c[v], 1);
    Tree::add_edge(c[v], c[u], 1);
  }
  for (int i = 1, u, v, w; i <= m; ++i) {
    u = edge[i << 1].f, v = edge[i << 1].t, w = edge[i << 1].w;
    if (w) continue;
    if (c[u] == c[v]) continue;
    if (c[u] > c[v]) swap(u, v);
    if (mp.count(make_pair(c[u], c[v]))) continue;
    mp[make_pair(c[u], c[v])] = 1;
    Tree::add_edge(c[u], c[v], 0);
    Tree::add_edge(c[v], c[u], 0);
  }
}
}  // namespace Tarjan
signed main() {
  Tarjan::solve();
  Tree::solve();
  return 0;
}
