#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
int n, m, ID;
int low[N], id[N];
vector<vector<pair<int, int> > > g;
struct edge {
  int x, y, t;
} edges[N];
bool bridges[N];
void dfs(int u, int p) {
  low[u] = id[u] = ID++;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (id[v] == -1) {
      dfs(v, u);
      if (low[v] > id[u]) bridges[g[u][i].second] = true;
      low[u] = min(low[u], low[v]);
    } else if (v != p)
      low[u] = min(low[u], id[v]);
  }
}
int par[N];
int find(int x) { return par[x] = par[x] == x ? x : find(par[x]); }
bool hav[N];
void join(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  par[y] = x;
}
int dist;
bool dfs(int u, int p, bool good) {
  if (u == dist) return good || hav[u];
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (v == p) continue;
    if (dfs(v, u, hav[u] || hav[v] || good || g[u][i].second)) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  g.resize(n);
  for (int i = 0; i < n; ++i) par[i] = i;
  memset(id, -1, sizeof id);
  for (int x, y, z, i = 0; i < m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    x--, y--;
    edges[i] = {x, y, z};
    g[x].push_back({y, i});
    swap(x, y);
    g[x].push_back({y, i});
  }
  dfs(0, -1);
  for (int i = 0; i < m; ++i) {
    if (bridges[i]) continue;
    join(edges[i].x, edges[i].y);
  }
  int x, y;
  scanf("%d%d", &x, &y);
  x--, y--;
  g.clear();
  g.resize(n);
  bool xf = false, yf = false;
  for (int i = 0; i < n; ++i) find(i);
  for (int i = 0; i < m; ++i) {
    if (bridges[i]) {
      g[par[edges[i].x]].push_back({par[edges[i].y], edges[i].t});
      g[par[edges[i].y]].push_back({par[edges[i].x], edges[i].t});
      continue;
    }
    if (edges[i].t) hav[par[edges[i].x]] = true;
  }
  dist = par[y];
  if (dfs(par[x], -1, false))
    puts("YES");
  else
    puts("NO");
  return 0;
}
