#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300000;
const int MAX_M = 300000;
const int INF = 1 << 30;
vector<int> nbrs[MAX_N], gnbrs[MAX_N];
pair<int, int> aes[MAX_N];
int gids[MAX_N], prvs[MAX_N];
bool gds[MAX_N], ags[MAX_N];
void bcc_visit(const vector<int> nbrs[], int v, int u,
               vector<pair<int, int> >& brdg, vector<vector<int> >& tecomp,
               stack<int>& roots, stack<int>& S, vector<bool>& inS,
               vector<int>& num, int& time) {
  num[v] = ++time;
  S.push(v);
  inS[v] = true;
  roots.push(v);
  const vector<int>& nbrv = nbrs[v];
  for (vector<int>::const_iterator vit = nbrv.begin(); vit != nbrv.end();
       vit++) {
    const int& w = *vit;
    if (num[w] == 0)
      bcc_visit(nbrs, w, v, brdg, tecomp, roots, S, inS, num, time);
    else if (u != w && inS[w])
      while (num[roots.top()] > num[w]) roots.pop();
  }
  if (v == roots.top()) {
    brdg.push_back(pair<int, int>(u, v));
    tecomp.push_back(vector<int>());
    for (;;) {
      int w = S.top();
      S.pop();
      inS[w] = false;
      tecomp.back().push_back(w);
      if (v == w) break;
    }
    roots.pop();
  }
}
void calc_bcc(const int n, const vector<int> nbrs[],
              vector<pair<int, int> >& brdg, vector<vector<int> >& tecomp) {
  vector<int> num(n);
  vector<bool> inS(n);
  stack<int> roots, S;
  int time = 0;
  for (int u = 0; u < n; u++)
    if (num[u] == 0) {
      bcc_visit(nbrs, u, n, brdg, tecomp, roots, S, inS, num, time);
      brdg.pop_back();
    }
}
bool find_edge(int n, pair<int, int> es[], int u, int v) {
  if (u > v) swap(u, v);
  pair<int, int> p(u, v);
  int k = lower_bound(es, es + n, p) - es;
  return (k < n && es[k] == p);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int aen = 0;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--, y--;
    nbrs[x].push_back(y);
    nbrs[y].push_back(x);
    if (z) aes[aen++] = pair<int, int>(x, y);
  }
  int st, gl;
  scanf("%d%d", &st, &gl);
  st--, gl--;
  vector<pair<int, int> > brdg;
  vector<vector<int> > tecomp;
  calc_bcc(n, nbrs, brdg, tecomp);
  if (false) {
    for (int i = 0; i < tecomp.size(); i++) {
      for (int j = 0; j < tecomp[i].size(); j++) printf(" %d", tecomp[i][j]);
      putchar('\n');
    }
    for (int i = 0; i < brdg.size(); i++)
      printf("(%d,%d)", brdg[i].first, brdg[i].second);
    putchar('\n');
  }
  memset(gids, -1, sizeof(gids));
  for (int i = 0; i < tecomp.size(); i++)
    for (int j = 0; j < tecomp[i].size(); j++) gids[tecomp[i][j]] = i;
  for (int i = 0; i < brdg.size(); i++) {
    int u = gids[brdg[i].first], v = gids[brdg[i].second];
    gnbrs[u].push_back(v);
    gnbrs[v].push_back(u);
  }
  int aem = 0;
  for (int i = 0; i < aen; i++) {
    int u = gids[aes[i].first], v = gids[aes[i].second];
    if (u != v) {
      if (u > v) swap(u, v);
      aes[aem++] = pair<int, int>(u, v);
    } else
      ags[u] = true;
  }
  aen = aem;
  sort(aes, aes + aen);
  int gst = gids[st], ggl = gids[gl];
  gds[gst] = true, prvs[gst] = -1;
  queue<int> q;
  q.push(gst);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (u == ggl) break;
    vector<int>& gnbru = gnbrs[u];
    for (vector<int>::iterator vit = gnbru.begin(); vit != gnbru.end(); vit++) {
      int v = *vit;
      if (!gds[v]) {
        gds[v] = true, prvs[v] = u;
        q.push(v);
      }
    }
  }
  for (int u = ggl; u >= 0; u = prvs[u]) {
    if (ags[u]) {
      puts("YES");
      return 0;
    }
    int v = prvs[u];
    if (v >= 0 && find_edge(aen, aes, u, v)) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}
