#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1e6;
struct edge {
  int v, r, c;
};
int t = 0, c = 0;
int pre[MAXN];
vector<edge> E[MAXN];
set<pair<int, int> > bridges;
inline void add_edge(int u, int v) {
  E[u].push_back(edge({v, ((int)((E[v]).size())), -1}));
  E[v].push_back(edge({u, ((int)((E[u]).size())) - 1, -1}));
}
int dfs(int u, int p = -1) {
  pre[u] = ++t;
  int lu = pre[u], lv;
  for (edge &e : E[u]) {
    if (!pre[e.v]) {
      lv = dfs(e.v, u);
      lu = min(lu, lv);
      if (lv == pre[e.v]) bridges.insert(minmax(u, e.v));
    } else if (e.v != p)
      lu = min(lu, pre[e.v]);
  }
  return lu;
}
void make_graph(int n) {
  for (int i = (0); i < (n); ++i)
    if (!pre[i]) dfs(i);
}
vector<int> artifacts;
int parent[MAXN];
bool srtifacts[MAXN];
void spread(int a) {
  srtifacts[a] = true;
  for (auto &e : E[a]) {
    if (!bridges.count(make_pair(a, e.v)) && !srtifacts[e.v]) {
      spread(e.v);
    }
  }
}
bool visited[MAXN];
void find_b(int a) {
  visited[a] = true;
  for (auto &e : E[a]) {
    if (!visited[e.v]) {
      visited[e.v] = true;
      parent[e.v] = a;
      find_b(e.v);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ver_cnt = n;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    if (c) {
      add_edge(a, ver_cnt);
      add_edge(b, ver_cnt);
      artifacts.push_back(ver_cnt);
      ver_cnt++;
    } else {
      add_edge(a, b);
    }
  }
  int a, b;
  scanf("%d%d", &a, &b);
  a--;
  b--;
  n = ver_cnt;
  make_graph(n);
  for (auto i : bridges) {
    bridges.insert(make_pair(i.second, i.first));
  }
  for (auto i : artifacts) {
    spread(i);
  }
  parent[a] = -1;
  find_b(a);
  int xd = b;
  while (xd >= 0) {
    if (srtifacts[xd]) {
      printf("YES");
      return 0;
    }
    xd = parent[xd];
  }
  printf("NO");
}
