#include <bits/stdc++.h>
using namespace std;
const int mx = 3e5 + 10;
vector<int> g[mx], w[mx], h[mx], t[mx];
int us[mx], vs[mx], wuv[mx];
int lyr[mx], low[mx], color[mx];
int p[mx];
int artifact[mx];
int gp(int u) { return (u == p[u] ? u : p[u] = gp(p[u])); }
void join(int u, int v, int art) {
  int pu = gp(u), pv = gp(v);
  artifact[pu] |= art;
  artifact[pv] |= art;
  if (pu == pv) return;
  p[pu] = pv;
  artifact[pv] |= artifact[pu];
}
void dfs(int u, int pu) {
  color[u] = 1;
  low[u] = lyr[u];
  for (int i = 0; i < int(g[u].size()); i++) {
    int v = g[u][i];
    bool add = false;
    if (color[v] == 0) {
      lyr[v] = 1 + lyr[u];
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] < lyr[v]) add = true;
    } else if (color[v] == 1 && v != pu) {
      low[u] = min(low[u], lyr[v]);
      add = true;
    }
    if (add) join(u, v, w[u][i]);
  }
  color[u] = 2;
}
void go(int u, int pu) {
  for (int i = 0; i < int(h[u].size()); i++) {
    int v = h[u][i];
    if (v != pu) {
      artifact[v] |= artifact[u];
      artifact[v] |= t[u][i];
      go(v, u);
    }
  }
}
int main() {
  int n, m, u, v, c;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &u, &v, &c);
    g[u].push_back(v);
    g[v].push_back(u);
    w[u].push_back(c);
    w[v].push_back(c);
    us[i] = u, vs[i] = v, wuv[i] = c;
  }
  for (int i = 0; i <= n; i++) p[i] = i;
  scanf("%d %d", &u, &v);
  dfs(u, u);
  for (int i = 0; i < m; i++) {
    int x = us[i], y = vs[i], c = wuv[i];
    int px = gp(x), py = gp(y);
    if (px != py) {
      h[px].push_back(py);
      h[py].push_back(px);
      t[px].push_back(c);
      t[py].push_back(c);
    }
  }
  go(gp(u), gp(u));
  if (artifact[gp(v)])
    puts("YES");
  else
    puts("NO");
  return 0;
}
