#include <bits/stdc++.h>
using namespace std;
const int MAXN = 8e5 + 10, MAXM = 1e7 + 10;
const int INF = INT_MAX, SINF = 0x3f3f3f3f;
const long long llINF = LLONG_MAX;
const int MOD = 1e9 + 7, mod = 998244353;
const int inv2 = 5e8 + 4;
int n, m, s, t;
vector<pair<int, int> > E;
int head[MAXN], ecnt;
struct Edge {
  int v, w, nxt;
} e[MAXN];
void add_edge(int u, int v, int w) {
  e[++ecnt] = {v, w, head[u]}, head[u] = ecnt;
  e[++ecnt] = {u, w, head[v]}, head[v] = ecnt;
}
int dfn[MAXN], low[MAXN], tot;
stack<int> st;
int cir[MAXN], cirnum, sz[MAXN];
void tarjan(int u, int f) {
  dfn[u] = low[u] = ++tot;
  st.push(u);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    if (!dfn[v]) {
      tarjan(v, u);
      low[u] = min(low[u], low[v]);
    } else if (!cir[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    cir[u] = ++cirnum;
    while (st.top() != u) {
      cir[st.top()] = cirnum;
      st.pop();
    }
    st.pop();
  }
}
bool vis[MAXN];
vector<int> g[MAXN];
void dfs(int u, int p) {
  vis[u] = 1;
  p += sz[u];
  if (u == cir[t]) {
    if (p)
      puts("YES");
    else
      puts("NO");
    exit(0);
  }
  for (auto v : g[u]) {
    if (v < 0 && !vis[-v]) dfs(-v, 1);
    if (v > 0 && !vis[v]) dfs(v, p);
  }
}
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_edge(u, v, w);
    if (w) E.push_back({u, v});
  }
  scanf("%d%d", &s, &t);
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i, 0);
  for (auto j : E) {
    if (cir[j.first] == cir[j.second]) sz[cir[j.first]]++;
  }
  for (int i = 1; i <= n; i++)
    for (int j = head[i]; j; j = e[j].nxt) {
      int v = cir[e[j].v], u = cir[i];
      if (u != v) {
        if (e[j].w) {
          g[u].push_back(-v);
          g[v].push_back(-u);
        } else {
          g[u].push_back(v);
          g[v].push_back(u);
        }
      }
    }
  for (int i = 1; i <= cirnum; i++) {
    sort((g[i]).begin(), (g[i]).end());
    g[i].resize(unique((g[i]).begin(), (g[i]).end()) - g[i].begin());
  }
  if (sz[cir[s]] || sz[cir[t]]) return puts("YES"), 0;
  dfs(cir[s], 0);
  puts("NO");
  return 0;
}
