#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > adjlist[300005];
bool visited[300005];
vector<pair<int, int> > btree[300005];
bool isbridge[300005];
int comp[300005];
int pa[300005];
int arr[300005];
int ti = 0;
int dfs0(int s) {
  visited[s] = 1;
  arr[s] = ti++;
  vector<pair<int, pair<int, int> > >::iterator it;
  int x = arr[s] + 1;
  for (it = adjlist[s].begin(); it != adjlist[s].end(); it++) {
    if (visited[it->first]) {
      if (it->first != pa[s]) {
        x = min(x, arr[it->first]);
      }
    } else {
      pa[it->first] = s;
      int y = dfs0(it->first);
      if (y > arr[s]) {
        isbridge[it->second.second] = 1;
      }
      x = min(x, y);
    }
  }
  return x;
}
int cmpno = 1;
bool artifact[300005];
void dfs1(int s, int cmp) {
  comp[s] = cmp;
  visited[s] = 1;
  vector<pair<int, pair<int, int> > >::iterator it;
  for (it = adjlist[s].begin(); it != adjlist[s].end(); it++) {
    if (!visited[it->first]) {
      if (isbridge[it->second.second]) {
        cmpno++;
        btree[cmp].push_back(make_pair(cmpno, it->second.first));
        btree[cmpno].push_back(make_pair(cmp, it->second.first));
        dfs1(it->first, cmpno);
      } else {
        if (it->second.first) artifact[cmp] = 1;
        dfs1(it->first, cmp);
      }
    } else {
      if (comp[it->first] == cmp && it->second.first) artifact[cmp] = 1;
    }
  }
}
int flag = 0;
int a, b;
void dfs(int s, int f) {
  visited[s] = 1;
  f = f | artifact[s];
  if (comp[b] == s) {
    flag = f;
    return;
  }
  vector<pair<int, int> >::iterator it;
  for (it = btree[s].begin(); it != btree[s].end(); it++) {
    if (!visited[it->first]) {
      dfs(it->first, f | it->second);
    }
  }
}
int main() {
  int n, m, i, j, k, w;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d", &j, &k, &w);
    adjlist[j].push_back(make_pair(k, make_pair(w, i)));
    adjlist[k].push_back(make_pair(j, make_pair(w, i)));
  }
  scanf("%d %d", &a, &b);
  dfs0(1);
  memset(visited, 0, sizeof(visited));
  dfs1(1, 1);
  memset(visited, 0, sizeof(visited));
  dfs(comp[a], 0);
  if (flag)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
