#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
vector<int> N[500005], G[500005];
int ts, top, scc, dfn[500005], low[500005], fa[500005], stk[500005], sz[500005],
    deg[500005];
void dfs(int u, int d, int p) {
  int sec = 0, sz;
  dfn[u] = low[u] = d;
  sz = d > 1;
  stk[++top] = u;
  for (auto v : N[u]) {
    if (!dfn[v]) {
      dfs(v, d + 1, u);
      low[u] = min(low[u], low[v]);
    } else if (v != p || sec++)
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    do {
      fa[stk[top]] = u;
    } while (stk[top--] != u);
  }
}
map<pair<int, int>, int> ok;
bool vis[500005], able[500005], has[500005];
void walk(int u, int p) {
  vis[u] = true;
  for (auto v : G[u])
    if (!vis[v]) walk(v, u);
  for (auto v : G[u])
    if (v != p) able[u] = able[u] || able[v];
}
bool judge(int u, int p) {
  vis[u] = true;
  bool o = has[u];
  for (auto v : G[u])
    if (able[v] && !vis[v]) o = o || judge(v, u);
  for (auto v : G[u])
    if (able[v] && v != p) o = o || ok[pair<int, int>(min(u, v), max(u, v))];
  return o;
}
int main() {
  int n, m, a, b, c;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a >> b >> c;
    N[a].push_back(b);
    N[b].push_back(a);
    ok[pair<int, int>(min(a, b), max(a, b))] = c;
  }
  cin >> a >> b;
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) dfs(i, 1, 0);
  memset(has, 0, sizeof(has));
  for (auto p : ok)
    if (fa[p.first.first] == fa[p.first.second])
      has[fa[p.first.first]] = has[fa[p.first.first]] || p.second;
  for (int i = 1; i <= n; ++i) {
    for (auto j : N[i])
      if (fa[i] != fa[j]) {
        G[fa[i]].push_back(fa[j]);
        ok[pair<int, int>(min(fa[i], fa[j]), max(fa[i], fa[j]))] =
            ok[pair<int, int>(min(i, j), max(i, j))];
      }
  }
  a = fa[a];
  b = fa[b];
  memset(vis, 0, sizeof(vis));
  memset(able, 0, sizeof(able));
  able[b] = true;
  walk(a, 0);
  if (able[a]) {
    memset(vis, 0, sizeof(vis));
    if (judge(a, 0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  } else
    cout << "NO" << endl;
}
