#include <bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 5;
int Head[MX], erear;
struct Edge {
  int u, v, nxt, z;
} E[MX << 1];
void edge_init() {
  erear = 0;
  memset(Head, -1, sizeof(Head));
}
void edge_add(int u, int v, int z) {
  E[erear].u = u;
  E[erear].v = v;
  E[erear].z = z;
  E[erear].nxt = Head[u];
  Head[u] = erear++;
}
int n, m;
int DFN[MX], Low[MX], dsz;
int Stack[MX], inStack[MX], Belong[MX], bsz, ssz;
int A[MX];
void trajan(int u, int e) {
  inStack[u] = 1;
  Stack[++ssz] = u;
  DFN[u] = Low[u] = ++dsz;
  for (int i = Head[u]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if ((i ^ 1) == e) continue;
    if (!DFN[v]) {
      trajan(v, i);
      Low[u] = min(Low[u], Low[v]);
    } else if (inStack[v]) {
      Low[u] = min(Low[u], Low[v]);
    }
  }
  if (DFN[u] == Low[u]) {
    bsz++;
    int v;
    do {
      v = Stack[ssz--];
      inStack[v] = 0;
      Belong[v] = bsz;
    } while (ssz && v != u);
  }
}
void tarjan_solve(int n) {
  dsz = bsz = ssz = 0;
  memset(DFN, 0, sizeof(DFN));
  for (int i = 1; i <= n; i++) {
    if (!DFN[i]) trajan(i, -1);
  }
}
bool DFS(int st, int ed, int f, int s) {
  s |= A[st];
  if (st == ed) return s;
  for (int i = Head[st]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == f) continue;
    if (DFS(v, ed, st, s | E[i].z)) return true;
  }
  return false;
}
int main() {
  edge_init();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, z;
    scanf("%d%d%d", &u, &v, &z);
    edge_add(u, v, z);
    edge_add(v, u, z);
  }
  tarjan_solve(n);
  int etot = erear;
  edge_init();
  for (int i = 0; i < etot; i++) {
    int u = Belong[E[i].u], v = Belong[E[i].v];
    if (u == v)
      A[u] |= E[i].z;
    else
      edge_add(u, v, E[i].z);
  }
  int st, ed;
  scanf("%d%d", &st, &ed);
  if (DFS(Belong[st], Belong[ed], -1, 0)) {
    printf("YES\n");
  } else
    printf("NO\n");
  return 0;
}
