#include <bits/stdc++.h>
using namespace std;
class BCCBridge {
 public:
  int n, bcc;
  vector<int> low;
  vector<int> dft;
  vector<int> where;
  vector<vector<int>> v;
  BCCBridge(int _n) {
    bcc = 0;
    n = _n;
    low.resize(_n + 5);
    dft.resize(_n + 5);
    v.resize(_n + 5);
    where.resize(_n + 5);
  }
  void add_edge(int x, int y) {
    v[x].push_back(y);
    v[y].push_back(x);
  }
  void dfs(int x, int f, vector<int>& st) {
    dft[x] = low[x] = dft[f] + 1;
    st.push_back(x);
    for (auto it : v[x])
      if (it != f) {
        if (!dft[it]) {
          dfs(it, x, st);
          low[x] = min(low[x], low[it]);
        } else {
          low[x] = min(low[x], dft[it]);
        }
      }
    if (low[x] == dft[x]) {
      bcc++;
      while (st.back() != x) {
        where[st.back()] = bcc;
        st.pop_back();
      }
      where[x] = bcc;
      st.pop_back();
    }
  }
  void find_BCC() {
    vector<int> st(n + 5);
    dfs(1, 0, st);
  }
};
const int NMAX = 300005;
int n, m, start, finish;
int a[NMAX], b[NMAX], c[NMAX];
int good[NMAX];
BCCBridge g(NMAX);
vector<pair<int, int>> v[NMAX];
void dfs_tree(int x, int f, int ok) {
  ok |= good[x];
  if (x == finish) {
    printf("%s\n", ok ? "YES" : "NO");
    exit(0);
  }
  for (auto it : v[x])
    if (it.first != f) dfs_tree(it.first, x, ok || it.second);
}
int main() {
  cin.sync_with_stdio(false);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    g.add_edge(a[i], b[i]);
  }
  scanf("%d%d", &start, &finish);
  g.find_BCC();
  for (int i = 1; i <= m; i++)
    if (g.where[a[i]] != g.where[b[i]]) {
      v[g.where[a[i]]].push_back(make_pair(g.where[b[i]], c[i]));
      v[g.where[b[i]]].push_back(make_pair(g.where[a[i]], c[i]));
    } else {
      if (c[i]) good[g.where[a[i]]] = 1;
    }
  start = g.where[start];
  finish = g.where[finish];
  dfs_tree(start, 0, 0);
  return 0;
}
