#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 5;
const int M = 300000 + 5;
struct EDGE {
  int v, next, c;
} edge[M << 1];
int first[N], low[N], dfn[N], belong[N], sta[M], instack[M], num[N];
int g, cnt, top, scc;
int min(int a, int b) { return a < b ? a : b; }
void AddEdge(int u, int v, int c) {
  edge[g].v = v;
  edge[g].c = c;
  edge[g].next = first[u];
  first[u] = g++;
}
void Tarjan(int u, int fa) {
  int v;
  low[u] = dfn[u] = ++cnt;
  sta[++top] = u;
  instack[u] = 1;
  for (int i = first[u]; i != -1; i = edge[i].next) {
    v = edge[i].v;
    if (i == (fa ^ 1)) continue;
    if (!dfn[v]) {
      Tarjan(v, i);
      low[u] = min(low[u], low[v]);
    } else if (instack[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    scc++;
    while (1) {
      v = sta[top--];
      instack[v] = 0;
      belong[v] = scc;
      if (v == u) break;
    }
  }
}
int vis[N];
vector<pair<int, int> > G[N];
int Bfs(int be, int en) {
  queue<pair<int, int> > Q;
  while (!Q.empty()) Q.pop();
  memset(vis, 0, sizeof(vis));
  Q.push(make_pair(be, num[be]));
  vis[be] = 1;
  while (!Q.empty()) {
    pair<int, int> now = Q.front();
    Q.pop();
    if (now.first == en) return now.second;
    int siz = G[now.first].size();
    for (int i = 0; i < siz; i++) {
      int next = G[now.first][i].first;
      if (vis[next]) continue;
      vis[next] = 1;
      Q.push(make_pair(next, now.second + num[next] + G[now.first][i].second));
    }
  }
}
int main() {
  int n, m, target = 0, be, en;
  scanf("%d%d", &n, &m);
  g = cnt = top = scc = 0;
  memset(first, -1, sizeof(first));
  memset(low, 0, sizeof(low));
  memset(dfn, 0, sizeof(dfn));
  memset(num, 0, sizeof(num));
  memset(instack, 0, sizeof(instack));
  for (int u, v, c, i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &c);
    AddEdge(u, v, c);
    AddEdge(v, u, c);
    target += c;
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) Tarjan(1, -1);
  for (int i = 1; i <= n; i++) {
    for (int j = first[i]; j != -1; j = edge[j].next) {
      int v = edge[j].v;
      if (belong[i] != belong[v]) {
        G[belong[i]].push_back(make_pair(belong[v], edge[j].c));
      } else
        num[belong[i]] += edge[j].c;
    }
  }
  for (int i = 1; i <= scc; i++) num[i] /= 2;
  scanf("%d%d", &be, &en);
  if (Bfs(belong[be], belong[en]))
    puts("YES");
  else
    puts("NO");
}
