#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<bool, int>>> adj[300001];
int low[300001];
int tin[300001];
int timer;
bool id_b[300001];
vector<pair<pair<int, int>, bool>> bridges;
bool check[300001];
void find_bridges(int r, int p) {
  check[r] = 1;
  timer++;
  tin[r] = timer;
  low[r] = timer;
  int i = 0;
  for (auto x : adj[r]) {
    if (x.first != p) {
      if (check[x.first]) {
        low[r] = min(low[r], tin[x.first]);
      } else {
        find_bridges(x.first, r);
        low[r] = min(low[r], low[x.first]);
        if (low[x.first] > tin[r]) {
          bridges.push_back(
              {{min(x.first, r), max(x.first, r)}, x.second.first});
          id_b[x.second.second] = 0;
        }
      }
    }
    i++;
  }
}
bool check2[300001];
int family[300001];
bool good_f[300001];
void find_family(int r, int p, int f) {
  check2[r] = 1;
  family[r] = f;
  for (auto x : adj[r]) {
    if (x.first != p) {
      if (x.second.first and id_b[x.second.second]) good_f[f] = 1;
      if ((!check2[x.first]) and id_b[x.second.second]) {
        find_family(x.first, r, f);
      }
    }
  }
}
vector<pair<int, bool>> adj2[300001];
bool ans = 0;
int b;
void dfs(int r, int p, int g) {
  if (good_f[r]) g = 1;
  if (r == b) ans = g;
  for (auto x : adj2[r]) {
    if (x.first != p) {
      if (x.second)
        dfs(x.first, r, 1);
      else
        dfs(x.first, r, g);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    bool t;
    cin >> u >> v >> t;
    adj[u].push_back({v, {t, i}});
    adj[v].push_back({u, {t, i}});
    id_b[i] = 1;
  }
  find_bridges(1, -1);
  for (int i = 1; i <= n; i++) {
    if (!check2[i]) find_family(i, -1, i);
  }
  for (auto x : bridges) {
    adj2[family[x.first.first]].push_back({family[x.first.second], x.second});
    adj2[family[x.first.second]].push_back({family[x.first.first], x.second});
  }
  int a;
  cin >> a >> b;
  a = family[a];
  b = family[b];
  dfs(a, -1, 0);
  if (ans)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
