#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAXN = 300005;
vector<int> edges[MAXN];
int depth[MAXN];
int up[MAXN];
vector<pair<int, int> > bied[MAXN];
int val[MAXN];
void get(int node, int p = 0) {
  depth[node] = depth[p] + 1;
  for (int g : edges[node]) {
    if (depth[g] == 0) get(g, node);
  }
}
void dfs(int node, int p = 0) {
  up[node] = depth[node];
  for (int g : edges[node]) {
    if (g == p) continue;
    if (depth[g] == depth[node] + 1) {
      dfs(g, node);
      up[node] = min(up[node], up[g]);
    } else
      up[node] = min(up[node], depth[g]);
  }
}
int p[MAXN];
int find(int a) {
  if (p[a] == 0) return a;
  return p[a] = find(p[a]);
}
void merge(int a, int b) {
  a = find(a), b = find(b);
  if (a == b) return;
  p[a] = b;
}
void go(int node, int p = 0) {
  if (node != 1 && up[node] <= depth[p]) merge(node, p);
  for (int g : edges[node]) {
    if (g == p) continue;
    if (depth[g] < depth[node]) {
      merge(g, node);
    } else if (depth[g] == depth[node] + 1) {
      go(g, node);
    }
  }
}
int answer = 0;
void illu(int start, int end, int cur = 0, int p = 0) {
  cur += val[start];
  if (start == end) {
    if (cur) answer = 1;
    return;
  }
  for (pair<int, int> t : bied[start]) {
    if (t.first == p) continue;
    illu(t.first, end, cur + t.second, start);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  vector<pair<pair<int, int>, int> > ed;
  for (int g = 1; g <= m; g++) {
    int a, b, c;
    cin >> a >> b >> c;
    ed.push_back(pair<pair<int, int>, int>(pair<int, int>(a, b), c));
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  get(1);
  dfs(1);
  go(1);
  for (int g = 0; g < ed.size(); g++) {
    int a = ed[g].first.first, b = ed[g].first.second, c = ed[g].second;
    a = find(a);
    b = find(b);
    if (a == b) {
      val[a] = max(val[a], c);
    } else {
      bied[a].push_back(pair<int, int>(b, c));
      bied[b].push_back(pair<int, int>(a, c));
    }
  }
  int f, s;
  cin >> f >> s;
  illu(find(f), find(s));
  if (answer)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
