#include <bits/stdc++.h>
const int MAXN = 3e5 + 5;
int n, m;
struct Edge {
  int to, w, nxt;
} e[MAXN << 1];
int head[MAXN], cnt = 1;
inline void add(int u, int v, int w) {
  e[++cnt] = (Edge){v, w, head[u]};
  head[u] = cnt;
  e[++cnt] = (Edge){u, w, head[v]};
  head[v] = cnt;
}
int bel[MAXN], tot;
int dfn[MAXN], low[MAXN];
int st[MAXN], tp;
inline void dfs(int v, int fe = 0) {
  static int ts = 0;
  dfn[v] = low[v] = ++ts;
  st[++tp] = v;
  for (int i = head[v]; i; i = e[i].nxt) {
    if ((fe >> 1) == (i >> 1)) continue;
    if (!dfn[e[i].to]) {
      dfs(e[i].to, i);
      low[v] = std::min(low[v], low[e[i].to]);
    } else {
      low[v] = std::min(low[v], dfn[e[i].to]);
    }
  }
  if (low[v] == dfn[v]) {
    int x = -1;
    ++tot;
    while (x != v) {
      x = st[tp--];
      bel[x] = tot;
    }
  }
}
std::vector<std::pair<int, int> > G[MAXN];
bool col[MAXN], vis[MAXN];
inline void dfs1(int v, int fa = 0) {
  col[v] |= col[fa];
  for (auto x : G[v]) {
    if (x.first == fa) continue;
    col[x.first] |= x.second;
    dfs1(x.first, v);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add(u, v, w);
  }
  int s, t;
  scanf("%d%d", &s, &t);
  dfs(1);
  for (int v = 1; v <= n; ++v) {
    for (int i = head[v]; i; i = e[i].nxt) {
      if (bel[v] != bel[e[i].to]) {
        G[bel[v]].push_back(std::make_pair(bel[e[i].to], e[i].w));
      } else {
        col[bel[v]] |= e[i].w;
      }
    }
  }
  dfs1(bel[s]);
  puts(col[bel[t]] ? "YES" : "NO");
  return 0;
}
