#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int n;
vector<vector<pair<int, int> > > g;
vector<int> idx, low;
int DFSTime;
map<pair<int, int>, bool> isB;
int child = 0;
void DFS(int u, int p) {
  idx[u] = low[u] = ++DFSTime;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (idx[v] == 0) {
      if (p == -1) ++child;
      DFS(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] > idx[u]) {
        isB[make_pair(u, v)] = isB[make_pair(v, u)] = 1;
      }
    } else if (v != p)
      low[u] = min(low[u], idx[v]);
  }
}
int vis[N], cmp[N], cmpID;
void getcmp(int u) {
  vis[u] = 1;
  cmp[u] = cmpID;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first, s = g[u][i].second;
    if (!vis[v] && !isB[make_pair(u, v)]) getcmp(v);
  }
}
map<pair<int, int>, int> fromEdge;
map<int, pair<int, int> > fromwhere;
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (fromEdge.find({u, v}) == fromEdge.end())
      fromEdge[{u, v}] = fromEdge[{v, u}] = u;
    if (!vis[g[u][i].first]) {
      if (fromwhere.find(cmp[v]) == fromwhere.end()) fromwhere[cmp[v]] = {u, v};
      dfs(g[u][i].first);
    }
  }
}
int S, E;
void can(int u, int l, int r, int _l, int _r) {
  vis[u] = 1;
  if (u == E) {
    cout << "YES";
    exit(0);
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    int mn = min(u, v), mx = max(u, v);
    if ((mn == l && mx == r) || (mn == _l && mx == _r)) continue;
    if (!vis[v]) can(v, l, r, _l, _r);
  }
}
int main() {
  vector<pair<int, int> > rose;
  int e;
  cin >> n >> e;
  idx.resize(n + 10);
  low.resize(n + 10);
  g.resize(n + 10);
  for (int i = 0; i < e; ++i) {
    int a, b, z;
    cin >> a >> b >> z;
    --a;
    --b;
    if (z) rose.push_back(make_pair(a, b));
    g[a].push_back(make_pair(b, z));
    g[b].push_back(make_pair(a, z));
  }
  DFS(0, -1);
  cin >> S >> E;
  S--, E--;
  for (int i = 0; i < n; i++)
    if (!vis[i]) cmpID++, getcmp(i);
  for (int i = 0; i < rose.size(); i++)
    if (cmp[S] == cmp[rose[i].first] && cmp[S] == cmp[rose[i].second])
      return cout << "YES", 0;
    else if (cmp[E] == cmp[rose[i].first] && cmp[E] == cmp[rose[i].second])
      return cout << "YES", 0;
  memset(vis, 0, sizeof(vis));
  dfs(S);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < rose.size(); i++) {
    int l = rose[i].first, r = rose[i].second;
    int fromhere = fromEdge[{l, r}];
    pair<int, int> hereCMP = fromwhere[cmp[fromhere]];
    if (fromhere == l)
      can(r, min(l, r), max(l, r), min(hereCMP.first, hereCMP.second),
          max(hereCMP.first, hereCMP.second));
    else
      can(l, min(l, r), max(l, r), min(hereCMP.first, hereCMP.second),
          max(hereCMP.first, hereCMP.second));
  }
  cout << "NO";
  return 0;
}
