#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 3e5 + 10;
int n, m, a, b;
vector<pair<int, bool> > graph[maxn];
int cnt, dfn[maxn], low[maxn], par[maxn];
bool vis[maxn], brg[maxn];
int col[maxn];
bool nodeval[maxn];
vector<pair<int, bool> > newg[maxn];
queue<int> q;
bool dist[maxn];
void dfs1(int x, int fa) {
  vis[x] = 1;
  dfn[x] = low[x] = cnt++;
  par[x] = fa;
  for (int i = 0; i < graph[x].size(); i++) {
    int to = graph[x][i].first;
    if (to != fa) {
      if (vis[to]) {
        low[x] = min(low[x], dfn[to]);
      } else {
        dfs1(to, x);
        low[x] = min(low[x], low[to]);
      }
    }
  }
  if (low[x] == dfn[x] && x) {
    brg[x] = 1;
  }
  return;
}
void dfs2(int x) {
  vis[x] = 1;
  col[x] = cnt;
  for (int i = 0; i < graph[x].size(); i++) {
    int to = graph[x][i].first;
    if (!vis[to]) {
      if (brg[x] && par[x] == to) {
        continue;
      }
      if (brg[to] && par[to] == x) {
        continue;
      }
      dfs2(to);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    bool z;
    cin >> x >> y >> z;
    x--;
    y--;
    graph[x].push_back(make_pair(y, z));
    graph[y].push_back(make_pair(x, z));
  }
  cin >> a >> b;
  a--;
  b--;
  cnt = 0;
  dfs1(0, -1);
  cnt = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs2(i);
      cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < graph[i].size(); j++) {
      int to = graph[i][j].first;
      if (col[i] != col[to]) {
        newg[col[i]].push_back(make_pair(col[to], graph[i][j].second));
      } else {
        if (graph[i][j].second) {
          nodeval[col[i]] = 1;
        }
      }
    }
  }
  int s = col[a], t = col[b];
  memset(vis, 0, sizeof(vis));
  q.push(s);
  vis[s] = 1;
  dist[s] = nodeval[s];
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < newg[x].size(); i++) {
      int to = newg[x][i].first;
      if (!vis[to]) {
        vis[to] = 1;
        dist[to] = dist[x] | nodeval[to] | newg[x][i].second;
        q.push(to);
      }
    }
  }
  if (dist[t]) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}
