#include <bits/stdc++.h>
using namespace std;
int N, M, used[300007], ces, A, B, art[300007], use[300007];
vector<pair<int, int> > edges[300007];
vector<int> dedges[300007], redges[300007];
stack<int> Q;
struct node {
  int a, b, t;
} all[300007];
void read() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= M; i++) {
    scanf("%d %d %d", &all[i].a, &all[i].b, &all[i].t);
    edges[all[i].a].push_back(make_pair(all[i].b, i));
    edges[all[i].b].push_back(make_pair(all[i].a, i));
  }
  scanf("%d %d", &A, &B);
}
void dfs(int now) {
  for (int i = 0; i < edges[now].size(); i++)
    if (!used[edges[now][i].second]) {
      dedges[now].push_back(edges[now][i].first);
      redges[edges[now][i].first].push_back(now);
      used[edges[now][i].second] = 1;
      dfs(edges[now][i].first);
    }
}
void dfs2(int now) {
  used[now] = 2;
  for (int i = 0; i < dedges[now].size(); i++)
    if (used[dedges[now][i]] != 2) dfs2(dedges[now][i]);
  Q.push(now);
}
void dfs3(int now) {
  used[now] = ces;
  for (int i = 0; i < redges[now].size(); i++)
    if (!used[redges[now][i]]) dfs3(redges[now][i]);
}
void dfs4(int now, int t) {
  use[now] = 1;
  t = (t | art[now]);
  if (now == used[B]) {
    if (t)
      printf("YES\n");
    else
      printf("NO\n");
    return;
  }
  for (int i = 0; i < edges[now].size(); i++)
    if (!use[edges[now][i].first]) {
      dfs4(edges[now][i].first, (t | edges[now][i].second));
    }
}
void process() {
  dfs(1);
  for (int i = 1; i <= N; i++)
    if (used[i] != 2) dfs2(i);
  memset(used, 0, sizeof(used));
  int now;
  while (!Q.empty()) {
    now = Q.top();
    Q.pop();
    if (!used[now]) {
      ces++;
      dfs3(now);
    }
  }
  for (int i = 1; i <= M; i++) {
    if (all[i].t && used[all[i].a] == used[all[i].b]) art[used[all[i].a]] = 1;
  }
  for (int i = 1; i <= N; i++) edges[i].clear();
  for (int i = 1; i <= M; i++)
    if (used[all[i].a] != used[all[i].b]) {
      edges[used[all[i].a]].push_back(make_pair(used[all[i].b], all[i].t));
      edges[used[all[i].b]].push_back(make_pair(used[all[i].a], all[i].t));
    }
  dfs4(used[A], art[used[A]]);
}
int main() {
  read();
  process();
  return 0;
}
