#include <bits/stdc++.h>
using namespace std;
vector<int> v[302020], w[302020];
int z[302020], k[302020], e[302020], p[302020], A, B;
void haku(int s, int h) {
  if (z[s]) return;
  z[s] = h;
  e[s] = 1e9;
  for (unsigned int i = 0; i < v[s].size(); ++i) {
    int u = v[s][i], d = w[s][i];
    if (z[u] == 0) {
      p[u] = s;
      k[u] = k[s] | d;
      haku(u, h + 1);
      e[s] = min(e[s], e[u]);
      if (k[u] && e[u] <= h) k[s] = 1;
    } else if (z[u] < h - 1) {
      e[s] = min(e[s], z[u]);
      if (d) k[s] = 1;
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    v[a].push_back(b);
    v[b].push_back(a);
    w[a].push_back(c);
    w[b].push_back(c);
  }
  cin >> A >> B;
  haku(A, 1);
  int a = B, V = 0;
  while (a != 0) {
    if (k[a]) V = 1;
    a = p[a];
  }
  cout << (V == 1 ? "YES" : "NO");
}
