#include <bits/stdc++.h>
using namespace std;
struct ss {
  int v;
  int flag;
};
vector<ss> q[300001];
vector<ss> p[300001];
int liantong[300001], dfn[300001], low[300001], st[300001], ss, ed;
bool inst[300001], vis[300001];
int x[300001], y[300001], dis[300001], ans, ff[300001];
void tarjan(int u, int fa) {
  dfn[u] = ++dfn[0];
  low[u] = dfn[u];
  st[++st[0]] = u;
  inst[u] = 1;
  for (int i = 0; i < q[u].size(); ++i) {
    int v = q[u][i].v;
    if (v == fa) continue;
    if (!dfn[v]) tarjan(v, u);
    if (inst[v]) low[u] = min(low[v], low[u]);
  }
  if (dfn[u] == low[u]) {
    liantong[0]++;
    while (st[st[0]] != u) {
      liantong[st[st[0]]] = liantong[0];
      inst[st[st[0]]] = 0;
      st[0]--;
    }
    liantong[st[st[0]]] = liantong[0];
    inst[st[st[0]]] = 0;
    st[0]--;
  }
}
bool pd[300100];
void dfs(int now, bool flag) {
  if (pd[now]) flag = true;
  if (now == liantong[ed]) {
    if (flag)
      puts("YES");
    else
      puts("NO");
    return;
  }
  for (int i = 0; i < p[now].size(); i++) {
    int v = p[now][i].v, f = p[now][i].flag;
    if (!vis[v]) {
      vis[v] = true;
      dfs(v, flag | f);
    }
  }
  return;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &x[i], &y[i], &ff[i]);
    q[x[i]].push_back({y[i], ff[i]});
    q[y[i]].push_back({x[i], ff[i]});
  }
  scanf("%d %d", &ss, &ed);
  for (int i = 1; i <= n; ++i) {
    if (!dfn[i]) tarjan(i, 0);
  }
  for (int i = 1; i <= m; ++i) {
    if (liantong[x[i]] == liantong[y[i]] && ff[i]) pd[liantong[x[i]]] = true;
  }
  for (int i = 1; i <= m; i++) {
    if (liantong[x[i]] != liantong[y[i]]) {
      p[liantong[x[i]]].push_back({liantong[y[i]], ff[i]});
      p[liantong[y[i]]].push_back({liantong[x[i]], ff[i]});
    }
  }
  vis[liantong[ss]] = true;
  dfs(liantong[ss], 0);
  return 0;
}
