#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
const int M = 300000 + 10;
struct edge {
  int art, from, to, id;
} e[M];
vector<edge> bridge;
vector<edge> G[N], T[N];
int n, m, cmpN;
int s, t;
int cmp[N], dfn[N], low[N], artCnt[N], cont[N];
bool vis[N], bri[M], visp[N];
void dfs1(int u, int f, int &c) {
  vis[u] = true;
  dfn[u] = c++;
  low[u] = dfn[u];
  for (int i = 0; i < G[u].size(); i++) {
    if (vis[G[u][i].to] == false) {
      dfs1(G[u][i].to, u, c);
      low[u] = min(low[u], low[G[u][i].to]);
      if (dfn[u] < low[G[u][i].to])
        bridge.push_back(G[u][i]), bri[G[u][i].id] = true;
    } else if (G[u][i].to != f)
      low[u] = min(low[u], dfn[G[u][i].to]);
  }
}
void dfs2(int u, int f) {
  cmp[u] = f;
  for (int i = 0; i < G[u].size(); i++) {
    if (!cmp[G[u][i].to] && !bri[G[u][i].id]) {
      dfs2(G[u][i].to, f);
    }
  }
}
void cal() {
  for (int i = 1; i <= n; i++) {
    int u = cmp[i];
    for (int j = 0; j < G[i].size(); j++) {
      if (cmp[G[i][j].to] == u && G[i][j].art == 1) cont[u] = 1;
    }
  }
}
void dfs3(int u, int cnt) {
  visp[u] = true;
  artCnt[u] = cnt;
  for (int i = 0; i < T[u].size(); i++) {
    if (!visp[T[u][i].to]) {
      int st = cnt | cont[T[u][i].to] | T[u][i].art;
      dfs3(T[u][i].to, st);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &e[i].from, &e[i].to, &e[i].art);
    G[e[i].from].push_back((edge){e[i].art, e[i].from, e[i].to, i});
    G[e[i].to].push_back((edge){e[i].art, e[i].to, e[i].from, i});
  }
  scanf("%d%d", &s, &t);
  int ct = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs1(i, -1, ct);
  for (int i = 1; i <= n; i++) {
    if (!cmp[i]) ++cmpN, dfs2(i, cmpN);
  }
  for (int i = 0; i < bridge.size(); i++) {
    int u = bridge[i].to, v = bridge[i].from;
    int t = bridge[i].art, d = bridge[i].id;
    T[cmp[u]].push_back((edge){t, cmp[u], cmp[v], d});
    T[cmp[v]].push_back((edge){t, cmp[v], cmp[u], d});
  }
  cal();
  if (cmp[s] == cmp[t]) {
    if (cont[cmp[t]])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  } else {
    dfs3(cmp[s], 0);
    if (artCnt[cmp[t]] >= 1)
      cout << "YES" << endl;
    else {
      if (cont[cmp[s]] || cont[cmp[t]])
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
