#include <bits/stdc++.h>
using namespace std;
set<int> g[300001];
vector<int> cg[300001], tg[300001];
bool was[300001];
int cur, comp[300001], order[300001];
void dfs1(int v) {
  was[v] = true;
  for (set<int>::iterator i(g[v].begin()); i != g[v].end(); ++i) {
    tg[*i].push_back(v);
    g[*i].erase(v);
    if (!was[*i]) dfs1(*i);
  }
  order[++cur] = v;
}
void dfs2(int v) {
  comp[v] = cur;
  for (int i(0); i < tg[v].size(); ++i)
    if (!comp[tg[v][i]]) dfs2(tg[v][i]);
}
void dfs3(int v) {
  was[v] = true;
  for (set<int>::iterator i(g[v].begin()); i != g[v].end(); ++i)
    if (comp[v] != comp[*i]) {
      cg[comp[v]].push_back(comp[*i]);
      cg[comp[*i]].push_back(comp[v]);
    } else if (!was[*i])
      dfs3(*i);
}
bool dfs4(int v, int t, set<int> &path) {
  was[v] = true;
  if (v == t) {
    path.insert(v);
    return true;
  }
  for (int i(0); i < cg[v].size(); ++i)
    if (!was[cg[v][i]] && dfs4(cg[v][i], t, path)) {
      path.insert(v);
      return true;
    }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  set<pair<int, int> > target;
  cin >> n >> m;
  for (int i(0), u, v, c; i < m; ++i) {
    cin >> u >> v >> c;
    if (c) target.insert({u, v});
    g[u].insert(v);
    g[v].insert(u);
  }
  for (int i(1); i <= n; ++i)
    if (!was[i]) dfs1(i);
  cur = 0;
  for (int i(n); i; --i)
    if (!comp[order[i]]) {
      ++cur;
      dfs2(order[i]);
    }
  memset(was, false, sizeof was);
  for (int i(1); i <= n; ++i)
    if (!was[i]) dfs3(i);
  set<int> path;
  int s, t;
  cin >> s >> t;
  memset(was, false, sizeof was);
  dfs4(comp[s], comp[t], path);
  for (set<pair<int, int> >::iterator i(target.begin()); i != target.end(); ++i)
    if (path.count(comp[i->first]) && path.count(comp[i->second])) {
      cout << "YES";
      return 0;
    }
  cout << "NO";
}
