#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[312345], graph[312345];
vector<int> wei[312345];
vector<pair<int, int> > query;
int parent[312345], disc[312345], weight[312345], low[312345], vis[312345],
    isbridge[312345];
int tym, compno[312345], comp;
void dfs(int u, int ee) {
  vis[u] = 1;
  disc[u] = tym;
  tym++;
  low[u] = disc[u];
  for (int i = 0; i < graph[u].size(); i++) {
    int k = graph[u][i].first;
    int e = graph[u][i].second;
    if (!vis[k]) {
      parent[k] = u;
      dfs(k, e);
      low[u] = min(low[u], low[k]);
    } else if (e != ee)
      low[u] = min(low[u], disc[k]);
  }
  if (ee != -1 && low[u] == disc[u]) isbridge[ee] = 1;
}
void btree(int u, int cmp) {
  compno[u] = cmp;
  vis[u] = 1;
  for (int i = 0; i < graph[u].size(); i++) {
    int k = graph[u][i].first;
    int e = graph[u][i].second;
    if (!vis[k]) {
      if (isbridge[e]) {
        comp++;
        adj[cmp].push_back(make_pair(comp, wei[u][i]));
        adj[comp].push_back(make_pair(cmp, wei[u][i]));
        btree(k, comp);
      } else
        weight[cmp] |= wei[u][i], btree(k, cmp);
    } else if (!isbridge[e])
      weight[cmp] |= wei[u][i];
  }
}
int dfs1(int u, int p, int v, int w) {
  w |= weight[u];
  if (u == v) return w;
  for (int i = 0; i < adj[u].size(); i++) {
    int k = adj[u][i].first;
    if (k == p) continue;
    int y = dfs1(k, u, v, w | adj[u][i].second);
    if (y == 1) return 1;
    if (y == 0) return 0;
  }
  return -1;
}
int main() {
  int n, m, q, i, j, k, l;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    graph[u].push_back(make_pair(v, i));
    graph[v].push_back(make_pair(u, i));
    wei[u].push_back(w);
    wei[v].push_back(w);
  }
  tym = 1;
  for (i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, -1);
  for (i = 1; i <= n; i++) vis[i] = 0;
  comp = 1;
  for (i = 1; i <= n; i++)
    if (!vis[i]) btree(i, comp), comp++;
  int u, v;
  scanf("%d %d", &u, &v);
  if (dfs1(compno[u], compno[u], compno[v], 0))
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
