#include <bits/stdc++.h>
using namespace std;
const int MaxN = 3e5 + 10;
struct edge {
  int u, v;
  bool type;
};
int n, m, cnt, cntcc, s, t;
int low[MaxN], num[MaxN], p[MaxN], p1[MaxN], avail[MaxN];
bool can[MaxN];
vector<pair<int, int> > g[MaxN], newg[MaxN];
vector<int> targ[MaxN];
stack<int> st;
void dfs(int u, int pa) {
  num[u] = ++cnt;
  for (pair<int, int> v : g[u]) {
    if (v.second == pa) continue;
    if (!num[v.second]) {
      dfs(v.second, u);
      p[v.second] = u;
    } else if (num[v.second] < num[u] && p[u] != v.second)
      p1[v.second] = u;
  }
}
void tarjan(int u) {
  st.push(u);
  num[u] = low[u] = ++cnt;
  for (int v : targ[u]) {
    if (!avail[v]) {
      if (!num[v]) {
        tarjan(v);
        low[u] = min(low[u], low[v]);
      } else
        low[u] = min(low[u], num[v]);
    }
  }
  if (low[u] == num[u]) {
    cntcc++;
    int v = 1e9;
    while (v != u) {
      v = st.top();
      st.pop();
      avail[v] = cntcc;
    }
  }
}
void checkcc(int u) {
  num[u] = 1;
  for (auto [type, v] : g[u]) {
    if (avail[v] != avail[u]) continue;
    if (type == 1) can[avail[u]] = 1;
    if (!num[v]) checkcc(v);
  }
}
void dfsSCC(int u) {
  num[u] = 1;
  for (pair<int, int> v : newg[u]) {
    if (num[v.second]) continue;
    can[v.second] = (can[u] || v.first);
    dfsSCC(v.second);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x, y;
  bool type;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> type;
    g[x].push_back({type, y});
    g[y].push_back({type, x});
  }
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    num[i] = 0;
    for (pair<int, int> x : g[i]) {
      if (p[x.second] == i)
        targ[i].push_back(x.second);
      else if (p1[i] == x.second)
        targ[x.second].push_back(i);
    }
  }
  cnt = 0;
  tarjan(1);
  for (int i = 1; i <= n; i++) num[i] = 0;
  for (int i = 1; i <= n; i++)
    if (!num[i]) checkcc(i);
  for (int i = 1; i <= n; i++) {
    for (pair<int, int> v : g[i]) {
      if (avail[v.second] != avail[i]) {
        type =
            (can[avail[i]] == 1 || can[avail[v.second]] == 1 || v.first == 1);
        newg[avail[v.second]].push_back({type, avail[i]});
        newg[avail[i]].push_back({type, avail[v.second]});
      }
    }
  }
  cin >> s >> t;
  for (int i = 1; i <= cntcc; i++) num[i] = 0;
  dfsSCC(avail[s]);
  if (can[avail[t]])
    cout << "YES\n";
  else
    cout << "NO\n";
}
