#include <bits/stdc++.h>
using namespace std;
int n, m, s, e, c;
vector<pair<int, bool> > uadj[300100];
vector<int> adj[300100];
vector<int> radj[300100];
vector<pair<int, bool> > bccadj[300100];
vector<int> bcc;
stack<int> st;
int color[300100];
bool ctrl[300100], art[300100], lft[300100];
void find_directed_graph(int ind, int par) {
  ctrl[ind] = true;
  for (int i = 0; i < uadj[ind].size(); i++) {
    pair<int, bool> elem = uadj[ind][i];
    if (!lft[elem.first] && elem.first != par) {
      adj[ind].push_back(elem.first);
      radj[elem.first].push_back(ind);
    }
    if (!ctrl[elem.first]) {
      find_directed_graph(elem.first, ind);
    }
  }
  lft[ind] = true;
}
void dfs1(int ind) {
  ctrl[ind] = true;
  for (int i = 0; i < adj[ind].size(); i++) {
    int v = adj[ind][i];
    if (!ctrl[v]) dfs1(v);
  }
  st.push(ind);
}
void dfs2(int ind) {
  ctrl[ind] = true;
  bcc.push_back(ind);
  for (int i = 0; i < radj[ind].size(); i++) {
    int v = radj[ind][i];
    if (!ctrl[v]) dfs2(v);
  }
}
void lastDFS(int ind, bool ar) {
  ar |= art[ind];
  art[ind] |= ar;
  ctrl[ind] = true;
  for (int i = 0; i < bccadj[ind].size(); i++) {
    pair<int, bool> elem = bccadj[ind][i];
    if (ctrl[elem.first]) continue;
    lastDFS(elem.first, ar | elem.second);
  }
}
int main() {
  cin >> n >> m;
  for (int a, b, c, i = 0; i < m; i++) {
    cin >> a >> b >> c;
    uadj[a].push_back(make_pair(b, c));
    uadj[b].push_back(make_pair(a, c));
  }
  cin >> s >> e;
  memset(color, false, sizeof(color));
  memset(art, false, sizeof(art));
  memset(lft, false, sizeof(lft));
  memset(ctrl, false, sizeof(ctrl));
  find_directed_graph(1, -1);
  memset(ctrl, false, sizeof(ctrl));
  dfs1(1);
  memset(ctrl, false, sizeof(ctrl));
  while (st.size()) {
    int ind = st.top();
    st.pop();
    if (ctrl[ind]) continue;
    bcc = vector<int>();
    dfs2(ind);
    for (int i = 0; i < bcc.size(); i++) {
      color[bcc[i]] = c;
    }
    c++;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < uadj[i].size(); j++) {
      pair<int, bool> elem = uadj[i][j];
      if (color[i] != color[elem.first]) {
        bccadj[color[i]].push_back(make_pair(color[elem.first], elem.second));
      } else if (elem.second)
        art[color[elem.first]] = true;
    }
  }
  memset(ctrl, false, sizeof(ctrl));
  lastDFS(color[s], false);
  if (art[color[e]])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
