#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 4e5 + 10;
const int M = 11;
const double PI = acos(-1.0);
bool debug = false;
pair<int, int> edge[N];
vector<pair<int, int> > son[N];
int belong[N], tin[N], low[N], now_time, scc_cnt, cnt;
stack<int> s;
void dfs(int o, int id) {
  tin[o] = low[o] = ++now_time;
  s.push(o);
  for (auto it : son[o]) {
    int v = it.first;
    if (!tin[v]) dfs(v, it.second);
    if (!belong[v] && id != it.second) low[o] = min(low[o], low[v]);
  }
  if (tin[o] == low[o]) {
    scc_cnt++;
    int now;
    while (true) {
      now = s.top();
      s.pop();
      belong[now] = scc_cnt;
      if (now == o) break;
    }
  }
}
bool scc(int n, int a, int b) {
  for (int i = 1; i <= n; ++i) tin[i] = low[i] = belong[i] = 0;
  while (s.size()) s.pop();
  now_time = scc_cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (!belong[i]) dfs(i, 0);
  }
  if (belong[a] == belong[b]) {
    for (int i = 0; i < cnt; ++i) {
      if (belong[edge[i].first] == belong[edge[i].second] &&
          belong[edge[i].first] == belong[a])
        return true;
    }
    return false;
  } else
    return false;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y, z; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    if (z) edge[cnt++] = {x, y};
    son[x].push_back({y, i});
    son[y].push_back({x, i});
  }
  int a, b;
  scanf("%d%d", &a, &b);
  son[a].push_back({b, m + 1});
  son[b].push_back({a, m + 1});
  if (scc(n, a, b))
    puts("YES");
  else
    puts("NO");
  return 0;
}
