#include <bits/stdc++.h>
using namespace std;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1e9, 1e9);
vector<vector<int>> g[300008], t[300008];
int t1[300008], t2[300008], T, u[300008];
set<pair<int, int>> st;
void dfs(int x, int px) {
  t1[x] = t2[x] = T++, u[x] = 1;
  for (auto& i : g[x])
    if (i[0] != px && !u[i[0]]) {
      dfs(i[0], x);
      t2[x] = min(t2[x], t2[i[0]]);
      if (t2[i[0]] > t1[x]) st.insert({x, i[0]});
    } else if (i[0] != px)
      t2[x] = min(t2[x], t1[i[0]]);
}
void dfs1(int x) {
  u[x] = T;
  for (auto& i : g[x])
    if (st.find({x, i[0]}) == st.end() && st.find({i[0], x}) == st.end()) {
      t1[T] += i[1];
      if (!u[i[0]]) dfs1(i[0]);
    } else if (u[i[0]])
      t[u[i[0]]].push_back({u[x], i[1]}), t[u[x]].push_back({u[i[0]], i[1]});
}
void dfs2(int x, int px) {
  t2[x] += t2[px] + t1[x];
  for (auto& i : t[x])
    if (i[0] != px) t2[i[0]] += i[1], dfs2(i[0], x);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, x, y, z, a, b;
  cin >> n >> m;
  while (m--) {
    cin >> x >> y >> z;
    g[--x].push_back({--y, z});
    g[y].push_back({x, z});
  }
  cin >> a >> b, --a, --b;
  dfs(a, a);
  fill(u, u + n + 2, 0);
  T = 1;
  for (int i = 0; i < n; ++i)
    if (!u[i]) t1[T] = 0, dfs1(i), ++T;
  if (t1[u[a]] || t1[u[b]]) {
    cout << "YES";
    exit(0);
  }
  fill(t2, t2 + n + 2, 0);
  dfs2(u[a], u[a]);
  cout << (t2[u[b]] ? "YES" : "NO");
}
