#include <bits/stdc++.h>
using namespace std;
int gr[1 << 20];
int un(int first) {
  if (gr[first] == first) return first;
  return gr[first] = un(gr[first]);
}
void join(int a, int b, int *d) {
  a = un(a), b = un(b);
  if (d[a] < d[b]) swap(a, b);
  gr[a] = b;
}
int n, m;
vector<pair<int, int> > E[1 << 20];
int st, en;
int dep[1 << 20];
int bio[1 << 20];
void bcc(int id, int p) {
  bio[id] = 1;
  for (auto t : E[id])
    if (t.first != p) {
      if (bio[un(t.first)] == 1) {
        join(id, t.first, dep);
        continue;
      }
      assert(bio[un(t.first)] != 2);
      dep[t.first] = dep[id] + 1;
      bcc(t.first, id);
      if (dep[un(t.first)] <= dep[id]) join(t.first, id, dep);
    }
  bio[id] = 2;
}
bool has[1 << 20];
vector<pair<int, int> > E2[1 << 20];
pair<bool, bool> dfs(int id, int p) {
  if (bio[id]++) return {false, false};
  if (id == un(en)) return {true, has[id]};
  for (auto t : E2[id])
    if (t.first != p) {
      auto first = dfs(t.first, id);
      if (first.first) return {true, first.second | t.second | has[id]};
    }
  return {false, false};
}
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = (int)(0); i < (int)(1 << 20); ++i) gr[i] = i;
  cin >> n >> m;
  for (int i = (int)(0); i < (int)(m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    E[a].push_back({b, c});
    E[b].push_back({a, c});
  }
  cin >> st >> en;
  bcc(1, 1);
  memset(bio, 0, sizeof bio);
  for (int i = (int)(1); i < (int)(n + 1); ++i)
    for (auto t : E[i]) {
      int a = un(i), b = un(t.first), c = t.second;
      if (a == b)
        has[a] |= c;
      else
        E2[a].push_back({b, c});
    }
  for (int i = (int)(0); i < (int)(1 << 20); ++i)
    sort(E2[i].begin(), E2[i].end(),
         [](pair<int, int> first, pair<int, int> second) {
           return first.second > second.second;
         });
  auto R = dfs(un(st), un(st));
  if (R.second)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
