#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
vector<vector<pair<int, int> > > g, T;
int n, m, dfs_low[N], dfs_num[N], cnt = 0, P[N], a, b;
bool bridge[N], can[N], vis[N], can2[N];
void DFS(int node, int prnt) {
  vis[node] = true;
  dfs_low[node] = dfs_num[node] = cnt++;
  for (int i = 0; i < g[node].size(); i++) {
    int newnode = g[node][i].first;
    if (newnode == prnt) continue;
    if (vis[newnode])
      dfs_low[node] = min(dfs_low[node], dfs_num[newnode]);
    else {
      DFS(newnode, node);
      dfs_low[node] = min(dfs_low[node], dfs_low[newnode]);
      if (dfs_num[node] < dfs_low[newnode]) bridge[g[node][i].second] = true;
    }
  }
}
int Find(int u) { return (u == P[u] ? u : P[u] = Find(P[u])); }
bool DFS2(int node, int prnt, bool one) {
  if (can2[node]) one = true;
  if (node == b) return one;
  for (int i = 0; i < T[node].size(); i++) {
    int newnode = T[node][i].first;
    if (newnode == prnt) continue;
    if (DFS2(newnode, node, (T[node][i].second == 1 ? 1 : one))) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  g.resize(n + 1);
  T.resize(n + 1);
  for (int i = 1; i <= n; i++) P[i] = i;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    can[i] = w;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  scanf("%d%d", &a, &b);
  DFS(1, -1);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (i > g[i][j].first) continue;
      if (bridge[g[i][j].second]) continue;
      int u = Find(i);
      int v = Find(g[i][j].first);
      P[u] = v;
      if (can2[u] || can[g[i][j].second]) can2[v] = true;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (i > g[i][j].first) continue;
      if (!bridge[g[i][j].second]) continue;
      int u = Find(i);
      int v = Find(g[i][j].first);
      T[u].push_back(make_pair(v, can[g[i][j].second]));
      T[v].push_back(make_pair(u, can[g[i][j].second]));
    }
  }
  a = Find(a);
  b = Find(b);
  if (DFS2(a, -1, 0))
    puts("YES");
  else
    puts("NO");
  return 0;
}
