#include <bits/stdc++.h>
using namespace std;
inline long long QuickPow(long long x, long long y) {
  long long Res = 1, Temp = x;
  while (y) {
    if (y & 1) Res = Res * Temp % 1000000007;
    Temp = Temp * Temp % 1000000007;
    y /= 2;
  }
  return Res;
}
inline void Swap(long long &x, long long &y) {
  long long Temp = x;
  x = y;
  y = Temp;
}
inline long long Max(long long x, long long y) { return x > y ? x : y; }
inline long long Min(long long x, long long y) { return x < y ? x : y; }
inline void read(long long &x) {
  x = 0;
  long long f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
struct node {
  long long v, w;
  node() {}
  node(long long V, long long W) {
    v = V;
    w = W;
  }
};
long long Dfn[300005], Low[300005], Cnt, Col, Bel[300005], Size[300005];
bool InStack[300005];
stack<long long> S;
vector<node> NG[300005], G[300005];
void Tarjan(long long x, long long Pre) {
  Dfn[x] = Low[x] = ++Cnt;
  S.push(x);
  InStack[x] = 1;
  int l = G[x].size();
  for (register long long i = 0; i < l; ++i) {
    long long to = G[x][i].v;
    if (to == Pre) continue;
    if (!Dfn[to]) {
      Tarjan(to, x);
      Low[x] = Min(Low[x], Low[to]);
    } else if (InStack[to])
      Low[x] = Min(Low[x], Dfn[to]);
  }
  if (Dfn[x] == Low[x]) {
    Col++;
    long long u;
    do {
      Size[Col]++;
      u = S.top();
      S.pop();
      InStack[u] = 0;
      Bel[u] = Col;
    } while (u != x);
  }
}
bool Vis[300005], Can[300005];
void Link(long long x) {
  Vis[x] = 1;
  int l = G[x].size();
  for (register long long i = 0; i < l; ++i) {
    long long to = G[x][i].v;
    if (Bel[x] == Bel[to] && G[x][i].w) Can[Bel[x]] = 1;
    if (Bel[x] != Bel[to]) NG[Bel[x]].push_back(node(Bel[to], G[x][i].w));
    if (Vis[to]) continue;
    Link(to);
  }
}
long long Dep[300005], Fa[300005];
void Build(long long x, long long Pre) {
  Dep[x] = Dep[Pre] + 1;
  Fa[x] = Pre;
  int l = NG[x].size();
  for (register long long i = 0; i < l; ++i) {
    long long to = NG[x][i].v;
    if (to == Pre) continue;
    Build(to, x);
  }
}
bool Alive, Pan[300005];
void Baoli(long long x, long long End, bool Alive) {
  Alive |= Can[x];
  if (x == End) {
    if (Alive)
      printf("YES");
    else
      printf("NO");
    exit(0);
  }
  Pan[x] = 1;
  int l = NG[x].size();
  for (register long long i = 0; i < l; ++i) {
    long long to = NG[x][i].v;
    if (Pan[to]) continue;
    Baoli(to, End, Alive | NG[x][i].w);
  }
}
int main() {
  long long n, m;
  read(n);
  read(m);
  for (register long long i = 1; i <= m; ++i) {
    long long u, v, w;
    read(u);
    read(v);
    read(w);
    G[u].push_back(node(v, w));
    G[v].push_back(node(u, w));
  }
  for (register long long i = 1; i <= n; ++i)
    if (!Dfn[i]) Tarjan(i, i);
  for (register long long i = 1; i <= n; ++i)
    if (!Vis[i]) Link(i);
  Build(1, 1);
  long long u, v;
  read(u);
  read(v);
  u = Bel[u], v = Bel[v];
  Baoli(u, v, 0);
  return 0;
}
