#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 3e5 + 4;
vector<int> v[N];
vector<pair<int, int>> tree[N];
int parent[N], x[N], y[N], have[N], stock[N];
int find(int x) {
  if (parent[x] == x) return x;
  parent[x] = find(parent[x]);
  return parent[x];
}
void merge(int i, int j) {
  int pi = find(i), pj = find(j);
  if (pi == pj) return;
  stock[pj] |= stock[pi];
  parent[pi] = pj;
}
int low[N], num[N], tim;
bool visit[N], is_bridge[N];
void dfs(int node, int pe) {
  visit[node] = 1;
  low[node] = num[node] = tim++;
  for (int it : v[node])
    if (it != pe) {
      int here = x[it] ^ y[it] ^ node;
      if (!visit[here]) {
        dfs(here, it);
        low[node] = min(low[node], low[here]);
      } else
        low[node] = min(low[node], num[here]);
    }
  if (pe != -1) {
    if (low[node] == num[node])
      is_bridge[pe] = 1;
    else
      merge(x[pe], y[pe]);
  }
}
void bridge_tree(int n, int m) {
  for (int i = 1; i < n + 1; i++) parent[i] = i;
  for (int i = 1; i < n + 1; i++)
    if (!visit[i]) dfs(i, -1);
  for (int i = 0; i < m; i++) {
    if (is_bridge[i]) {
      int px = find(x[i]), py = find(y[i]);
      tree[px].emplace_back(py, have[i]);
      tree[py].emplace_back(px, have[i]);
    } else {
      stock[find(x[i])] |= have[i];
    }
  }
}
int final = 0;
void dfs_tree(int node, int par, int des, int flag) {
  flag |= stock[node];
  if (node == des) final = flag;
  for (auto it : tree[node])
    if (it.first != par) {
      int hflag = flag | it.second;
      dfs_tree(it.first, node, des, hflag);
    }
}
void calc(int pa, int push_back) {
  pa = find(pa);
  push_back = find(push_back);
  if (pa == push_back) {
    final = stock[pa];
    return;
  }
  dfs_tree(pa, -1, push_back, 0);
}
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &x[i]);
    scanf("%d", &y[i]);
    cin >> have[i];
    v[x[i]].push_back(i);
    v[y[i]].push_back(i);
  }
  bridge_tree(n, m);
  int pa, push_back;
  scanf("%d", &pa);
  scanf("%d", &push_back);
  calc(pa, push_back);
  if (final)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
