#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 3e5 + 5;
int N, M, a, b;
vector<int> G[NMAX];
int Low[NMAX], Nivel[NMAX];
set<pair<int, int> > S;
vector<pair<pair<int, int>, int> > Edges;
int comp[NMAX];
bool viz[NMAX];
int Artifact[NMAX];
int nrcomp = 0;
vector<pair<int, int> > GComp[NMAX];
void Read() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> M;
  for (int i = 1; i <= M; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    G[x].push_back(y);
    G[y].push_back(x);
    Edges.push_back({{x, y}, z});
  }
  cin >> a >> b;
  for (int i = 1; i <= N; ++i) Nivel[i] = -1;
}
void Dfs(int node, int dad = 0, int lvl = 1) {
  Low[node] = Nivel[node] = lvl;
  for (auto it : G[node]) {
    if (it == dad) continue;
    if (Nivel[it] == -1) {
      Dfs(it, node, lvl + 1);
      Low[node] = min(Low[node], Low[it]);
      if (Low[it] > Low[node]) {
        S.insert({node, it});
        S.insert({it, node});
      }
    } else
      Low[node] = min(Low[node], Nivel[it]);
  }
}
void Components(int node, int which) {
  viz[node] = 1;
  comp[node] = which;
  for (auto it : G[node]) {
    if (viz[it] || S.find({node, it}) != S.end()) continue;
    Components(it, which);
  }
}
int Solve(int node, int now) {
  viz[node] = 1;
  now |= Artifact[node];
  if (node == b) return now;
  for (pair<int, int> it : GComp[node]) {
    if (viz[it.second]) continue;
    if (Solve(it.second, (now | it.first))) return 1;
  }
  return 0;
}
int main() {
  Read();
  Dfs(1);
  for (int i = 1; i <= N; ++i)
    if (!viz[i]) {
      ++nrcomp;
      Components(i, nrcomp);
    }
  for (int i = 0; i < M; ++i) {
    int x = Edges[i].first.first;
    int y = Edges[i].first.second;
    int z = Edges[i].second;
    if (comp[x] == comp[y])
      Artifact[comp[x]] = max(Artifact[comp[x]], z);
    else {
      GComp[comp[x]].push_back({z, comp[y]});
      GComp[comp[y]].push_back({z, comp[x]});
    }
  }
  for (int i = 1; i <= nrcomp; ++i) viz[i] = 0;
  a = comp[a];
  b = comp[b];
  int ans = Solve(a, 0);
  if (ans == 1)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
