#include <bits/stdc++.h>
using namespace std;
template <class T>
void chkmax(T& x, T y) {
  x = (x > y ? x : y);
}
template <class T>
void chkmin(T& x, T y) {
  x = (x < y ? x : y);
}
const int N = 3e5 + 5;
void bad() {
  printf("NO\n");
  exit(0);
}
void good() {
  printf("YES\n");
  exit(0);
}
int n, m, s, t, S, T;
vector<pair<int, int> > e[N], se[N];
int dfsn[N], low[N], kdfs;
int st[N], kst;
int scc[N], kscc;
bool vis[N], belong[N], have[N];
map<pair<int, int>, int> mp;
void dfs(int now, int from = -1) {
  vis[now] = 1;
  dfsn[now] = low[now] = ++kdfs;
  st[++kst] = now;
  for (auto u : e[now])
    if (u.first != from) {
      if (vis[u.first])
        chkmin(low[now], dfsn[u.first]);
      else {
        dfs(u.first, now);
        chkmin(low[now], low[u.first]);
      }
    }
  if (dfsn[now] == low[now]) {
    kscc++;
    do {
      scc[st[kst--]] = kscc;
    } while (st[kst + 1] != now);
  }
}
void solve(int now, int op, int from = -1) {
  if (now == scc[t]) {
    op ? good() : bad();
    return;
  }
  for (auto u : se[now])
    if (u.first != from) {
      solve(u.first, op | u.second | have[u.first], now);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(m); ++i) {
    int u, v, op;
    scanf("%d%d%d", &u, &v, &op);
    e[u].push_back(make_pair(v, op));
    e[v].push_back(make_pair(u, op));
  }
  scanf("%d%d", &s, &t);
  for (int i = 1; i < (int)(n + 1); ++i)
    if (!vis[i]) dfs(i);
  for (int i = 1; i < (int)(n + 1); ++i) {
    for (auto u : e[i]) {
      if (scc[i] == scc[u.first])
        have[scc[i]] |= u.second;
      else if (mp.count(make_pair(min(scc[i], scc[u.first]),
                                  max(scc[i], scc[u.first]))) == 0) {
        mp[make_pair(min(scc[i], scc[u.first]), max(scc[i], scc[u.first]))] =
            u.second;
        se[scc[i]].push_back(make_pair(scc[u.first], u.second));
        se[scc[u.first]].push_back(make_pair(scc[i], u.second));
      } else {
        mp[make_pair(min(scc[i], scc[u.first]), max(scc[i], scc[u.first]))] |=
            u.second;
      }
    }
  }
  solve(scc[s], have[scc[s]]);
  bad();
  return 0;
}
