#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1e5 + 10;
const int MAXM = 3 * 1e5 + 10;
vector<int> grafo[MAXN], tree[MAXN];
int vetor[MAXN], e1[MAXM], e2[MAXM], e3[MAXN], N, M;
int low[MAXN], num[MAXN], dfsPtr;
int processado[MAXN], distancia[MAXN];
int e4[MAXM], e5[MAXM], e6[MAXM], compId[MAXN], compAtual, possui[MAXN],
    jafoi[MAXN];
void dfs(int v, int p) {
  num[v] = low[v] = ++dfsPtr;
  for (int i : grafo[v]) {
    int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
    if (u == p) continue;
    if (num[u] == 0) {
      dfs(u, v);
      low[v] = min(low[v], low[u]);
    } else {
      low[v] = min(low[v], num[u]);
    }
  }
}
void build(int v, int p) {
  if (jafoi[v]) return;
  jafoi[v] = 1;
  for (int i : grafo[v]) {
    int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
    if (u == p) continue;
    if (num[v] < num[u]) {
      if (num[v] < low[u]) {
        compAtual++;
        compId[u] = compAtual;
        e4[i] = compId[v];
        e5[i] = compId[u];
        e6[i] = e3[i];
        tree[e4[i]].push_back(i);
        tree[e5[i]].push_back(i);
        build(u, v);
      } else {
        possui[compId[v]] |= e3[i];
        compId[u] = compId[v];
        build(u, v);
      }
    }
  }
}
void encontra(int v, int p, int alvo, int jatem) {
  jatem |= possui[v];
  if (v == alvo) {
    if (jatem)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    return;
  }
  for (int i : tree[v]) {
    int u = (e4[i] != v) ? (e4[i]) : (e5[i]);
    if (u == p) continue;
    encontra(u, v, alvo, jatem || e6[i]);
  }
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> e1[i] >> e2[i] >> e3[i];
    grafo[e1[i]].push_back(i);
    grafo[e2[i]].push_back(i);
  }
  int A, B;
  cin >> A >> B;
  dfs(1, -1);
  compId[1] = ++compAtual;
  build(1, -1);
  A = compId[A];
  B = compId[B];
  encontra(A, -1, B, 0);
  return 0;
}
