#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int mpow(int base, int exp);
const int N = 3e5 + 4;
vector<int> g[N];
vector<pair<int, int> > tree[N];
int U[N], comp_artifact[N], V[N], dis[N], Z[N], bridge[N], vis[N];
queue<int> Q[N];
int adj(int u, int e) { return (U[e] == u) ? V[e] : U[e]; }
int comp = 0;
int dfs0(int u, int edge) {
  static int T = 0;
  dis[u] = ++T;
  int i;
  int low = dis[u];
  for (i = 0; i < g[u].size(); i++) {
    int e = g[u][i];
    int v = adj(u, e);
    if (!dis[v])
      low = min(low, dfs0(v, e));
    else if (e != edge)
      low = min(low, dis[v]);
  }
  if (low == dis[u] && edge != -1) {
    bridge[edge] = 1;
  }
  return low;
}
void dfs1(int u) {
  int i;
  int curr = comp;
  dis[u] = curr;
  Q[curr].push(u);
  vis[u] = 1;
  while (Q[curr].size() != 0) {
    u = Q[curr].front();
    Q[curr].pop();
    for (i = 0; i < g[u].size(); i++) {
      int e = g[u][i];
      int v = adj(u, e);
      if (Z[e] && !bridge[e]) {
        comp_artifact[curr] = 1;
      }
      if (vis[v]) continue;
      if (bridge[e]) {
        comp++;
        tree[curr].push_back({comp, Z[e]});
        tree[comp].push_back({curr, Z[e]});
        dfs1(v);
      } else {
        dis[v] = curr;
        Q[curr].push(v);
        vis[v] = 1;
      }
    }
  }
}
int a, b;
int p[N], good[N];
void dfs2(int u, int par) {
  int v, i;
  int ans = 0;
  if (u == dis[b]) return;
  for (i = 0; i < tree[u].size(); i++) {
    pair<int, int> x = tree[u][i];
    int v = x.first;
    if (v == par) continue;
    p[v] = u;
    good[v] = x.second;
    dfs2(v, u);
    if (v == dis[b]) return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int i, n, m;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int u, v, z;
    cin >> u >> v >> z;
    U[i] = u - 1, V[i] = v - 1;
    Z[i] = z;
    g[u - 1].push_back(i);
    g[v - 1].push_back(i);
  }
  cin >> a >> b;
  a--;
  b--;
  memset(dis, 0, sizeof(dis));
  memset(bridge, 0, sizeof(bridge));
  for (i = 0; i < n; i++)
    if (!vis[i]) dfs0(i, -1);
  memset(vis, 0, sizeof(vis));
  dfs1(a);
  if (!vis[b]) {
    cout << "NO\n" << endl;
    return 0;
  }
  memset(vis, 0, sizeof(vis));
  dfs2(dis[a], -1);
  int u, v;
  v = dis[b], u = dis[a];
  int sahi = comp_artifact[v];
  while (v != u) {
    sahi = max(sahi, comp_artifact[v]);
    sahi = max(sahi, good[v]);
    v = p[v];
  }
  sahi = max(sahi, comp_artifact[u]);
  if (sahi)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long)result * base) % mod;
    base = ((long long)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
