#include <bits/stdc++.h>
using namespace std;
const int MAXN = 301 * 1001;
vector<int> tree[MAXN];
vector<pair<int, int> > yal2, a[MAXN], yal;
int mark[MAXN] = {}, t[MAXN] = {}, cl[MAXN] = {}, col[MAXN] = {}, c = 1;
int mark2[MAXN] = {}, par[MAXN] = {}, ans[MAXN] = {};
;
int dfs1(int u, int p, int par) {
  cl[u] = c;
  int ans = t[u];
  for (auto v : a[u]) {
    if (cl[v.first]) {
      if (v.second != p) ans = min(ans, t[v.first]);
      continue;
    }
    t[v.first] = t[u] + 1;
    ans = min(ans, dfs1(v.first, v.second, u));
  }
  if (ans == t[u] && par != -1) {
    mark[p] = 1;
    yal2.push_back({u, par});
  }
  return ans;
}
void dfs2(int u) {
  col[u] = c;
  for (auto v : a[u]) {
    if (mark[v.second] || col[v.first]) continue;
    dfs2(v.first);
  }
}
void dfs3(int u, int p) {
  for (auto v : tree[u]) {
    if (v == p) continue;
    t[v] = t[u] + 1;
    par[v] = u;
    dfs3(v, u);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x, y, z, ss, tt;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    a[x].push_back({y, i});
    a[y].push_back({x, i});
    if (z) yal.push_back({x, y}), mark2[i] = 1;
  }
  cin >> ss >> tt;
  dfs1(ss, -1, -1);
  c = 1;
  for (int i = 1; i <= n; i++) {
    if (!col[i]) {
      dfs2(i);
      c++;
    }
  }
  c--;
  for (auto u : yal2) {
    tree[col[u.first]].push_back(col[u.second]);
    tree[col[u.second]].push_back(col[u.first]);
  }
  ss = col[ss];
  tt = col[tt];
  t[ss] = 0;
  dfs3(ss, 0);
  for (auto u : yal) {
    if (t[col[u.first]] < t[col[u.second]]) {
      ans[col[u.second]] = 1;
    } else
      ans[col[u.first]] = 1;
  }
  while (tt) {
    if (ans[tt]) return cout << "YES", 0;
    tt = par[tt];
  }
  cout << "NO";
}
