#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
constexpr int N = 300001;
struct Ed {
  int u, v;
  bool s;
};
vector<pii> g[N], t[N];
int d[N], low[N], biconn[N];
bool scored[N], vis[N];
int tim = 1, compno = 1;
pii p[N];
void dfs(int u, int p) {
  low[u] = d[u] = tim++;
  for (const auto& pr : g[u]) {
    if (pr.first == p) continue;
    if (d[pr.first] != 0) {
      low[u] = min(low[u], d[pr.first]);
    } else {
      dfs(pr.first, u);
      low[u] = min(low[u], low[pr.first]);
    }
  }
}
void comp(int u, int p, int c) {
  if (biconn[u] != 0) return;
  if (low[u] == d[u]) c = ++compno;
  biconn[u] = c;
  for (const auto& pr : g[u]) {
    if (pr.second && biconn[pr.first] == c) scored[c] = true;
    if (pr.first == p && biconn[p] != c) {
      t[c].push_back({biconn[p], pr.second});
      t[biconn[p]].push_back({c, pr.second});
    } else if (biconn[pr.first] == 0)
      comp(pr.first, u, c);
  }
}
void solve() {
  int n, m, x, y, z, a, b;
  cin >> n >> m;
  while (m--) {
    cin >> x >> y >> z;
    g[x].push_back({y, z});
    g[y].push_back({x, z});
  }
  cin >> a >> b;
  dfs(a, -1);
  comp(a, -1, 1);
  a = biconn[a];
  b = biconn[b];
  queue<int> q;
  q.push(a);
  vis[a] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (const auto& v : t[u])
      if (!vis[v.first]) {
        p[v.first] = {u, v.second};
        q.push(v.first);
        vis[v.first] = true;
      }
  }
  bool ok = scored[a];
  while (!ok && b != a) {
    if (scored[b] || p[b].second) ok = true;
    b = p[b].first;
  }
  cout << (ok ? "YES\n" : "NO\n");
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
