#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int M = N;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
struct Edge {
  int u, v, w, nex;
} edges[M << 1];
int head[N], etot;
int dfn[N], dfs_clock;
int bcc_no[N], bcc_cnt;
int sta[N], top;
bool vis[M << 1];
int n, m, s, t;
void addEdge(int u, int v, int w) {
  edges[etot] = Edge{u, v, w, head[u]};
  head[u] = etot++;
}
void initGraph() {
  memset(head, -1, sizeof(int) * (n + 1));
  etot = 0;
}
int Tarjan(int u) {
  int lowu = dfn[u] = ++dfs_clock;
  sta[top++] = u;
  for (int i = head[u]; ~i; i = edges[i].nex) {
    int v = edges[i].v;
    if (!dfn[v]) {
      vis[i] = vis[i ^ 1] = true;
      lowu = min(lowu, Tarjan(v));
    } else if (!vis[i]) {
      vis[i] = vis[i ^ 1] = true;
      lowu = min(lowu, dfn[v]);
    }
  }
  if (lowu == dfn[u]) {
    ++bcc_cnt;
    int x;
    do {
      x = sta[--top];
      bcc_no[x] = bcc_cnt;
    } while (x != u);
  }
  return lowu;
}
void findBCC() {
  dfs_clock = bcc_cnt = top = 0;
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) Tarjan(i);
}
set<pair<int, int> > edge[N];
int cnt[N];
int d[N];
bool BFS() {
  memset(d, -1, sizeof(int) * (n + 1));
  memset(vis, false, sizeof(bool) * (n + 1));
  d[s] = cnt[s];
  vis[s] = true;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (auto p : edge[u]) {
      if (!vis[p.first]) {
        if (d[p.first] < d[u] + p.second) {
          d[p.first] = d[u] + p.second + cnt[p.first];
        }
        vis[p.first] = true;
        que.push(p.first);
      }
    }
  }
  return d[t] > 0;
}
int main() {
  scanf("%d%d", &n, &m);
  initGraph();
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addEdge(u, v, w);
    addEdge(v, u, w);
  }
  findBCC();
  scanf("%d%d", &s, &t);
  s = bcc_no[s];
  t = bcc_no[t];
  for (int i = 0; i < etot; ++i) {
    Edge &e = edges[i];
    int u = bcc_no[e.u], v = bcc_no[e.v];
    if (u == v) cnt[u] += e.w;
  }
  for (int i = 0; i < etot; ++i) {
    Edge &e = edges[i];
    int u = bcc_no[e.u], v = bcc_no[e.v];
    if (u != v) edge[u].insert(pair<int, int>(v, e.w + cnt[v]));
  }
  printf("%s\n", BFS() ? "YES" : "NO");
  return 0;
}
