#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > adj[300005], tree[300005];
vector<long long int> vv[300005];
long long int low[300005], tin[300005], c[300005], vis[300005], viss[300005],
    visss[300005], lvll[300005], t = 0, ans[300005];
map<pair<long long int, long long int>, long long int> m;
void dfs(long long int n, long long int par) {
  vis[n] = 1;
  tin[n] = low[n] = t++;
  for (auto x : adj[n]) {
    if (x.first == par) {
      continue;
    }
    if (vis[x.first] == 1) {
      low[n] = min(low[n], tin[x.first]);
    } else {
      dfs(x.first, n);
      low[n] = min(low[n], low[x.first]);
      if (low[x.first] > tin[n]) {
        m[{x.first, n}] = 1;
        m[{n, x.first}] = 1;
      }
    }
  }
}
long long int comp = 0;
void dfs1(long long int n) {
  long long int curr = comp;
  queue<long long int> q;
  c[n] = curr;
  vv[curr].push_back(n);
  visss[n] = 1;
  q.push(n);
  while (!q.empty()) {
    long long int r = q.front();
    vv[curr].push_back(r);
    q.pop();
    for (auto x : adj[r]) {
      if (visss[x.first] == 1) {
        continue;
      }
      if (m[{x.first, r}] == 1) {
        comp++;
        tree[curr].push_back({comp, x.second});
        tree[comp].push_back({curr, x.second});
        dfs1(x.first);
      } else {
        q.push(x.first);
        c[x.first] = curr;
        visss[x.first] = 1;
      }
    }
  }
}
long long int anss, fl;
long long int active[300005];
void dfs2(long long int n, long long int g) {
  viss[n] = 1;
  active[n] = 1;
  long long int i, j, k;
  if (n == g) {
    for (i = 0; i < 300002; i++) {
      if (active[i]) {
        for (j = 0; j < (long long int)vv[i].size(); j++) {
          for (k = 0; k < (long long int)adj[vv[i][j]].size(); k++) {
            if (m[{adj[vv[i][j]][k].first, vv[i][j]}] == 0) {
              anss += adj[vv[i][j]][k].second;
            }
          }
        }
      }
    }
    if (anss) fl = 1;
  }
  for (auto x : tree[n]) {
    if (viss[x.first] == 0) {
      anss += x.second;
      dfs2(x.first, g);
      anss -= x.second;
    }
  }
  active[n] = 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, mi, u, v, w, a, b, i, j, k;
  cin >> n >> mi;
  while (mi--) {
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  dfs(1, -1);
  dfs1(1);
  cin >> a >> b;
  if (c[a] == c[b]) {
    i = c[a];
    anss = 0;
    for (j = 0; j < (long long int)vv[i].size(); j++) {
      for (k = 0; k < (long long int)adj[vv[i][j]].size(); k++) {
        if (m[{adj[vv[i][j]][k].first, vv[i][j]}] == 0) {
          anss += adj[vv[i][j]][k].second;
        }
      }
    }
    if (anss) {
      cout << "YES";
    } else {
      cout << "NO";
    }
  } else {
    fl = 0;
    anss = 0;
    dfs2(c[a], c[b]);
    if (fl) {
      cout << "YES";
    } else {
      cout << "NO";
    }
  }
}
