#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300100;
int n, m, a, b1, c[MAXN], x, y, dis[MAXN], low[MAXN], b[MAXN];
vector<pair<int, int> > v[MAXN];
int bio[MAXN], tajm;
void dfs(int cvor, int par) {
  bio[cvor] = 1;
  tajm++;
  dis[cvor] = low[cvor] = tajm;
  for (int i = (0); i < int((int)v[cvor].size()); i++) {
    int ncvor = v[cvor][i].first;
    if (ncvor == par) continue;
    if (bio[ncvor] == 1) low[cvor] = min(low[cvor], dis[ncvor]);
    if (bio[ncvor]) continue;
    dfs(ncvor, cvor);
    low[cvor] = min(low[cvor], low[ncvor]);
    if (low[ncvor] > dis[cvor]) b[v[cvor][i].second] = 1;
  }
  bio[cvor] = 2;
}
void rek(int cvor) {
  bio[cvor] = 1;
  for (int i = (0); i < int((int)v[cvor].size()); i++) {
    int ncvor = v[cvor][i].first;
    if (b[v[cvor][i].second]) continue;
    if (c[v[cvor][i].second]) {
      puts("YES");
      exit(0);
    }
    if (bio[ncvor]) continue;
    rek(ncvor);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (0); i < int(m); i++) {
    scanf("%d %d %d", &a, &b1, &c[i]);
    v[a].push_back(make_pair(b1, i));
    v[b1].push_back(make_pair(a, i));
  }
  scanf("%d %d", &x, &y);
  v[x].push_back(make_pair(MAXN - 1, MAXN - 1));
  v[MAXN - 1].push_back(make_pair(x, MAXN - 1));
  v[y].push_back(make_pair(MAXN - 1, MAXN - 1));
  v[MAXN - 1].push_back(make_pair(y, MAXN - 1));
  dfs(x, -1);
  memset(bio, 0, sizeof bio);
  rek(x);
  puts("NO");
  return 0;
}
