#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > adj[400005];
vector<bool> visited;
vector<int> tin, low;
int timer;
set<pair<int, pair<int, int> > > bridgeset;
int nodeToComp[400005];
int s, e;
void IS_BRIDGE(int from, int to, int val) {
  bridgeset.insert({from, {to, val}});
  bridgeset.insert({to, {from, val}});
}
void dfs(int v, int p = -1) {
  visited[v] = true;
  tin[v] = low[v] = timer++;
  for (pair<int, int> x : adj[v]) {
    int to = x.first;
    if (to == p) continue;
    if (visited[to]) {
      low[v] = min(low[v], tin[to]);
    } else {
      dfs(to, v);
      low[v] = min(low[v], low[to]);
      if (low[to] > tin[v]) IS_BRIDGE(v, to, x.second);
    }
  }
}
void find_bridges() {
  bridgeset.clear();
  timer = 0;
  visited.assign(n + 1, false);
  tin.assign(n + 1, -1);
  low.assign(n + 1, -1);
  for (int i = 0; i < n; ++i) {
    if (!visited[i + 1]) dfs(i + 1);
  }
}
vector<pair<int, int> > components[400005];
bool artifacts[400005];
void dfsbc(int v, int comp) {
  visited[v] = 1;
  nodeToComp[v] = comp;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int to = adj[v][i].first;
    if (!(bridgeset.count({v, {to, 0}}) || bridgeset.count({v, {to, 1}})))
      if (adj[v][i].second) artifacts[comp] = 1;
    if (!visited[to])
      if (!(bridgeset.count({v, {to, 0}}) || bridgeset.count({v, {to, 1}}))) {
        dfsbc(to, comp);
      }
  }
}
void get_bcomponents() {
  int comp = 1;
  visited.assign(n + 1, false);
  for (int i = 0; i < n; i++) {
    if (!visited[i + 1]) {
      dfsbc(i + 1, comp);
      comp++;
    }
  }
}
bool solve = false;
void dfs0(int v, bool arti) {
  visited[v] = true;
  for (int i = 0; i < components[v].size(); i++) {
    int to = components[v][i].first;
    if (!visited[to]) {
      if (to == nodeToComp[e]) {
        if (arti || artifacts[to] || components[v][i].second) solve = true;
      }
      dfs0(to, (arti || artifacts[to] || components[v][i].second));
    }
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
  }
  cin >> s >> e;
  find_bridges();
  get_bcomponents();
  for (auto it : bridgeset) {
    components[nodeToComp[it.first]].push_back(
        {nodeToComp[it.second.first], it.second.second});
  }
  visited.assign(n + 1, false);
  if (nodeToComp[s] == nodeToComp[e]) solve = artifacts[nodeToComp[s]];
  dfs0(nodeToComp[s], artifacts[nodeToComp[s]]);
  if (solve)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
