#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
int n, m, a, b;
struct node {
  int to;
  int art;
  node(int i, int j) {
    to = i;
    art = j;
  }
};
list<node> g[300009];
list<pair<int, int> > connect[300009];
int disc[300009];
int low[300009];
bool visited[300009];
bool in[300009];
stack<int> s;
int block[300009];
int tim = 0;
int cnt = 0;
void tarjan(int i, int par) {
  tim++;
  disc[i] = tim;
  low[i] = tim;
  visited[i] = true;
  s.push(i);
  list<node>::iterator j;
  for (j = g[i].begin(); j != g[i].end(); j++) {
    int v = j->to;
    if (v == par) continue;
    if (disc[v] == 0) {
      tarjan(v, i);
      low[i] = min(low[i], low[v]);
    } else if (visited[v])
      low[i] = min(low[i], disc[v]);
  }
  if (disc[i] == low[i]) {
    cnt++;
    while (true) {
      int temp = s.top();
      s.pop();
      block[temp] = cnt;
      visited[temp] = false;
      if (temp == i) return;
    }
  }
}
bool sf[300009];
bool bfs() {
  queue<int> q;
  q.push(block[a]);
  sf[block[a]] = true;
  while (!q.empty()) {
    int temp = q.front();
    q.pop();
    list<pair<int, int> >::iterator ite;
    for (ite = connect[temp].begin(); ite != connect[temp].end(); ite++) {
      int v = ite->first;
      int ar = ite->second;
      if (sf[v]) continue;
      in[v] |= in[temp] | ar;
      q.push(v);
      sf[v] = true;
    }
  }
  if (in[block[b]])
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d", &n, &m);
  bool flag = false;
  cnt = 0;
  for (int i = 0; i < m; i++) {
    int temp1, temp2, temp3;
    scanf("%d%d%d", &temp1, &temp2, &temp3);
    g[temp1].push_back(node(temp2, temp3));
    g[temp2].push_back(node(temp1, temp3));
    if (temp3) flag = true;
  }
  scanf("%d%d", &a, &b);
  if (!flag) {
    cout << "NO" << endl;
    return 0;
  }
  tarjan(1, 0);
  for (int i = 1; i <= n; i++) {
    list<node>::iterator ite;
    for (ite = g[i].begin(); ite != g[i].end(); ite++) {
      int v = ite->to;
      int art = ite->art;
      if (block[i] == block[v]) {
        if (art == 1) in[block[i]] = true;
      } else {
        connect[block[i]].push_back(make_pair(block[v], art));
      }
    }
  }
  if (block[a] == block[b] && in[block[a]]) {
    cout << "YES" << endl;
    return 0;
  }
  if (bfs())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
