#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const long long ool = (long long)1e18;
const double eps = 1e-9;
const int MAX = 300009;
int n, m, N, dfs;
int src, dst;
vector<vector<pair<int, int> > > g;
vector<pair<pair<int, int>, int> > Edge;
int idx[MAX], low[MAX], vis[MAX], compOf[MAX];
int has[MAX];
vector<int> S;
vector<vector<int> > comp;
vector<vector<pair<int, int> > > dag;
void DFS(int u, int p) {
  vis[u] = 1;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i].first;
    int c = g[u][i].second;
    if (v != p) Edge.push_back(make_pair(make_pair(u, v), c));
    if (!vis[v]) DFS(v, u);
  }
}
void SCC(int u) {
  vis[u] = 1;
  idx[u] = low[u] = dfs++;
  S.push_back(u);
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i].first;
    if (idx[v] == 0) SCC(v);
    if (vis[v]) low[u] = min(low[u], low[v]);
  }
  if (idx[u] == low[u]) {
    comp.push_back(vector<int>());
    while (true) {
      int v = S.back();
      S.pop_back();
      vis[v] = 0;
      compOf[v] = comp.size() - 1;
      comp.back().push_back(v);
      if (u == v) break;
    }
  }
}
bool FIND(int u, int p, int ok) {
  if (u == dst) return ok;
  bool r = false;
  for (int i = 0; i < (int)dag[u].size(); i++) {
    int v = dag[u][i].first;
    int c = dag[u][i].second;
    if (v != p) {
      r = r || FIND(v, u, ok || has[v] || c);
    }
  }
  return r;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    g.clear();
    g.resize(n);
    Edge.clear();
    for (int i = 0; i < m; i++) {
      int u, v, c;
      scanf("%d%d%d", &u, &v, &c);
      --u, --v;
      g[u].push_back(make_pair(v, c));
      swap(u, v);
      g[u].push_back(make_pair(v, c));
    }
    scanf("%d%d", &src, &dst);
    --src, --dst;
    memset(vis, 0, sizeof vis);
    DFS(src, -1);
    g.clear();
    g.resize(n);
    for (int i = 0; i < (int)Edge.size(); i++) {
      int u = Edge[i].first.first;
      int v = Edge[i].first.second;
      int c = Edge[i].second;
      g[u].push_back(make_pair(v, c));
    }
    memset(idx, 0, sizeof idx);
    memset(vis, 0, sizeof vis);
    comp.clear();
    dfs = 1;
    for (int i = 0; i < n; i++)
      if (idx[i] == 0) SCC(i);
    N = (int)comp.size();
    dag.clear();
    dag.resize(N);
    memset(has, 0, sizeof has);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < (int)g[i].size(); j++) {
        int u = compOf[i];
        int v = compOf[g[i][j].first];
        if (u != v)
          dag[u].push_back(make_pair(v, g[i][j].second));
        else
          has[u] = has[u] || g[i][j].second;
      }
    }
    src = compOf[src];
    dst = compOf[dst];
    if (FIND(src, -1, has[src]))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
