#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const double eps = 1e-12;
template <typename T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
const int N = 300010;
int n, m, s, t;
int uu[N], vv[N], ww[N];
vector<int> v[N];
int timp, ebcc;
int dt[N], low[N], col[N];
int top, stk[N];
void tarjan(int x, int par = 0) {
  dt[x] = low[x] = ++timp;
  stk[++top] = x;
  for (int i = 0; i < v[x].size(); i++) {
    int y = v[x][i];
    if (y == par) continue;
    if (!dt[y]) {
      tarjan(y, x);
      low[x] = min(low[x], low[y]);
    } else
      low[x] = min(low[x], dt[y]);
  }
  if (dt[x] == low[x]) {
    ebcc++;
    int y;
    do {
      y = stk[top--];
      col[y] = ebcc;
    } while (y != x);
  }
}
bool ans;
bool mark[N], vis[N];
vector<int> w[N];
void dfs(int x, int par = 0) {
  vis[x] |= mark[x];
  for (int i = 0; i < w[x].size(); i++) {
    int y = w[x][i] >> 1, z = w[x][i] & 1;
    if (y == par) continue;
    vis[y] |= z;
    vis[y] |= vis[x];
    dfs(y, x);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &uu[i], &vv[i], &ww[i]);
    v[uu[i]].push_back(vv[i]);
    v[vv[i]].push_back(uu[i]);
  }
  tarjan(1);
  scanf("%d %d", &s, &t);
  for (int i = 0; i < m; i++) {
    if (col[uu[i]] == col[vv[i]]) {
      if (ww[i]) mark[col[uu[i]]] = 1;
    } else {
      int x = col[uu[i]], y = col[vv[i]];
      w[x].push_back(y << 1 | ww[i]);
      w[y].push_back(x << 1 | ww[i]);
    }
  }
  s = col[s], t = col[t];
  dfs(s, 0);
  puts(vis[t] ? "YES" : "NO");
  return 0;
}
