#include <bits/stdc++.h>
using namespace std;
const int N = 300003;
vector<int> v[N], val[N];
int a, b, n, m, numbering[N], low[N], father[N], down[N];
bool back[N];
void dfs(int x, int fa) {
  low[x] = numbering[x];
  back[x] = false;
  for (int i = v[x].size() - 1; i >= 0; i--)
    if (v[x][i] != fa) {
      if (numbering[v[x][i]] == 0) {
        numbering[v[x][i]] = numbering[x] + 1;
        father[v[x][i]] = x;
        down[v[x][i]] = val[x][i];
        dfs(v[x][i], x);
        low[x] = min(low[x], low[v[x][i]]);
        if ((val[x][i] == 1 || back[v[x][i]]) && low[v[x][i]] <= numbering[x])
          back[x] = true;
      } else if (numbering[v[x][i]] < numbering[x]) {
        low[x] = min(low[x], numbering[v[x][i]]);
        if (val[x][i] == 1) back[x] = true;
      }
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    v[x].push_back(y);
    v[y].push_back(x);
    val[x].push_back(z);
    val[y].push_back(z);
  }
  scanf("%d%d", &a, &b);
  numbering[a] = 1;
  down[a] = 0;
  dfs(a, 0);
  while (b != 0) {
    if (back[b] || down[b] == 1) {
      cout << "YES" << endl;
      return 0;
    }
    b = father[b];
  }
  cout << "NO" << endl;
  return 0;
}
