#include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m, Q;
const int N = 3e5 + 5;
struct edg {
  int to, nxt, w;
} e[N << 1], e1[N << 1];
int cnt = 1, cnt1, head1[N], head[N], dfn[N], low[N], st[N], tp, num, scc;
int dis[N], bel[N], val[N];
void add(int u, int v, int w) {
  cnt++;
  e[cnt].to = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
  e[cnt].w = w;
}
void add1(int u, int v, int w) {
  cnt1++;
  e1[cnt1].to = v;
  e1[cnt1].nxt = head1[u];
  head1[u] = cnt1;
  e1[cnt1].w = w;
}
void tarjan(int u, int f) {
  dfn[u] = low[u] = ++num;
  st[++tp] = u;
  for (int i = head[u]; i; i = e[i].nxt) {
    if (i == f) continue;
    int v = e[i].to;
    if (!dfn[v]) {
      tarjan(v, i ^ 1);
      low[u] = min(low[u], low[v]);
    } else
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    scc++;
    int x = -1;
    do {
      x = st[tp--];
      bel[x] = scc;
    } while (x != u);
  }
}
void dfs(int u, int f) {
  dis[u] += val[u];
  for (int i = head1[u]; i; i = e1[i].nxt) {
    int v = e1[i].to;
    if (v != f) {
      dis[v] = e1[i].w + dis[u];
      dfs(v, u);
    }
  }
}
void work() {
  scanf("%d%d", &n, &m);
  int u, v, w;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    add(u, v, w), add(v, u, w);
  }
  tarjan(1, 0);
  for (int u = 1; u <= n; u++)
    for (int i = head[u]; i; i = e[i].nxt)
      if (bel[u] != bel[e[i].to])
        add1(bel[u], bel[e[i].to], e[i].w);
      else
        val[bel[u]] += e[i].w;
  scanf("%d%d", &u, &v);
  u = bel[u], v = bel[v];
  dfs(u, 0);
  if (dis[v])
    puts("YES");
  else
    puts("NO");
}
}  // namespace FGF
int main() {
  FGF::work();
  return 0;
}
