#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pii = pair<ll, ll>;
vi num, st;
vector<vi> adj, comps;
ll Time, C;
ll dfs(ll at, ll par) {
  ll me = num[at] = ++Time, top = me;
  st.push_back(at);
  bool first = true;
  for (auto y : adj[at]) {
    if (y == par && first) {
      first = false;
      continue;
    }
    if (num[y]) {
      top = min(top, num[y]);
    } else {
      ll si = ll((st).size());
      ll up = dfs(y, at);
      top = min(top, up);
      if (up >= me) {
        if (up == me) {
          for (ll p = (si); p < ll(ll((st).size())); p++)
            comps[st[p]].push_back(C);
          comps[at].push_back(C++);
        }
        st.resize(si);
      }
      if (up > me) {
      }
    }
  }
  return top;
}
void bicomps() {
  num.assign(ll((adj).size()), 0);
  C = 0;
  comps.clear();
  comps.resize(ll((adj).size()));
  for (ll i = (0); i < ll(ll((adj).size())); i++)
    if (!num[i]) dfs(i, -1);
}
bool artifact[500005];
bool cartifact[500005];
ll uf[500005];
ll comp1[500005];
vector<pair<ll, bool>> adj2[500005];
vector<pair<ll, bool>> cadj[500005];
ll dest;
ll find(ll x) { return uf[x] < 0 ? x : uf[x] = find(uf[x]); }
void join(ll a, ll b) {
  a = find(a);
  b = find(b);
  if (a == b) return;
  if (uf[a] > uf[b]) swap(a, b);
  uf[a] += uf[b];
  uf[b] = a;
}
ll rdfs(ll cur, ll par) {
  ll res = cartifact[cur] ? 1 : 0;
  if (cur == dest) return res | 2;
  for (auto &p : cadj[cur])
    if (p.first != par) {
      ll dr = rdfs(p.first, cur);
      if (dr < 2) continue;
      return dr | res | p.second;
    }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  ll N, M;
  while (cin >> N >> M) {
    C = 0;
    memset(cartifact, 0, sizeof(cartifact));
    for (ll i = (0); i < ll(N); i++) {
      adj2[i].clear();
      cadj[i].clear();
    }
    adj.clear();
    adj.resize(N);
    for (ll i = (0); i < ll(M); i++) {
      ll a, b, z;
      cin >> a >> b >> z;
      a--;
      b--;
      adj2[a].emplace_back(b, z);
      adj2[b].emplace_back(a, z);
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    ll a;
    cin >> a >> dest;
    a--;
    dest--;
    bicomps();
    memset(uf, -1, sizeof(uf));
    for (ll i = (0); i < ll(N); i++) {
      assert(set<ll>(comps[i].begin(), comps[i].end()).size() ==
             ll((comps[i]).size()));
      if (comps[i].size() > 1) {
        ll firstc = *comps[i].begin();
        for (auto c : comps[i]) {
          join(firstc, c);
        }
      } else if (comps[i].size() == 0) {
        comps[i].push_back(C);
        C += 1;
      }
    }
    for (ll i = (0); i < ll(N); i++) {
      comp1[i] = find(*comps[i].begin());
    }
    for (ll i = (0); i < ll(N); i++) {
      for (auto &p : adj2[i]) {
        if (comp1[p.first] == comp1[i]) {
          cartifact[comp1[i]] |= p.second;
        } else {
          cadj[comp1[i]].emplace_back(comp1[p.first], p.second);
        }
      }
    }
    dest = comp1[dest];
    if (rdfs(comp1[a], -1) & 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
