#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1e5 + 10;
const int pN = 1e6;
const int INF = 0x3f3f3f3f;
const int MOD = 2009;
void add(long long &x, long long y) {
  x += y;
  x %= MOD;
}
int n, m;
struct Edge {
  int from, to, val, next;
};
Edge edge[MAXN * 2];
int head[MAXN], edgenum;
void init() {
  memset(head, (-1), sizeof(head));
  edgenum = 0;
}
void addEdge(int u, int v, int w) {
  Edge E = {u, v, w, head[u]};
  edge[edgenum] = E;
  head[u] = edgenum++;
}
int low[MAXN], dfn[MAXN];
bool Instack[MAXN];
stack<int> S;
int dfs_clock;
int ebcno[MAXN], ebc_cnt;
int val[MAXN];
map<pair<int, int>, int> fp;
void tarjan(int u, int fa) {
  int v, flag = 0;
  low[u] = dfn[u] = ++dfs_clock;
  S.push(u);
  Instack[u] = true;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    v = edge[i].to;
    if (v == fa && !flag) {
      flag = 1;
      continue;
    }
    if (!dfn[v]) {
      tarjan(v, u);
      low[u] = min(low[u], low[v]);
    } else if (Instack[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (low[u] == dfn[u]) {
    ebc_cnt++;
    for (;;) {
      v = S.top();
      S.pop();
      Instack[v] = false;
      ebcno[v] = ebc_cnt;
      if (v == u) break;
    }
  }
}
void find_cut(int l, int r) {
  memset(Instack, (false), sizeof(Instack));
  memset(low, (0), sizeof(low));
  memset(dfn, (0), sizeof(dfn));
  memset(ebcno, (0), sizeof(ebcno));
  dfs_clock = ebc_cnt = 0;
  for (int i = l; i <= r; i++) {
    if (!dfn[i]) {
      tarjan(i, -1);
    }
  }
}
struct New {
  int from, to, val, next;
};
New Map[MAXN * 2];
int H[MAXN], E;
void addMap(int u, int v, int w) {
  New T = {u, v, w, H[u]};
  Map[E] = T;
  H[u] = E++;
}
void suodian() {
  memset(H, (-1), sizeof(H));
  E = 0;
  memset(val, (0), sizeof(val));
  for (int i = 0; i < edgenum; i += 2) {
    int u = ebcno[edge[i].from];
    int v = ebcno[edge[i].to];
    int w = edge[i].val;
    if (u != v) {
      addMap(u, v, w);
      addMap(v, u, w);
    } else if (w) {
      val[u] = 1;
    }
  }
}
int dist[MAXN];
bool vis[MAXN];
void BFS(int s, int t) {
  memset(dist, (0), sizeof(dist));
  memset(vis, (false), sizeof(vis));
  queue<int> Q;
  Q.push(s);
  dist[s] = val[s];
  vis[s] = true;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = H[u]; i != -1; i = Map[i].next) {
      New E = Map[i];
      if (!vis[E.to]) {
        if (dist[E.to] < dist[u] + E.val + val[E.to]) {
          dist[E.to] = dist[u] + E.val + val[E.to];
        }
        Q.push(E.to);
        vis[E.to] = true;
      }
    }
  }
  printf(dist[t] ? "YES\n" : "NO\n");
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  fp.clear();
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addEdge(u, v, w);
    addEdge(v, u, w);
  }
  find_cut(1, n);
  suodian();
  int s, t;
  scanf("%d%d", &s, &t);
  BFS(ebcno[s], ebcno[t]);
  return 0;
}
