#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > G, G1;
vector<bool> used;
stack<int> stk;
vector<int> edges, W, id, low, W2;
int pre, cnt;
void tdfs(int u, int pi) {
  used[u] = true;
  low[u] = pre++;
  int mn = low[u];
  stk.push(u);
  for (int v, i = 0; i < G[u].size(); i++) {
    v = G[u][i].first;
    if (v == pi) continue;
    if (!used[v]) {
      tdfs(v, u);
    }
    mn = min(mn, low[v]);
  }
  if (mn < low[u]) {
    low[u] = mn;
    return;
  }
  int v;
  do {
    v = stk.top();
    stk.pop();
    id[v] = cnt;
    low[v] = G.size();
  } while (v != u);
  cnt++;
}
void init(vector<vector<pair<int, int> > > g, int V) {
  G = g;
  used.assign(V, false);
  stk = stack<int>();
  id = low = vector<int>(V, 0);
  pre = cnt = 0;
  for (int u = 0; u < V; u++) {
    if (!used[u]) {
      tdfs(u, -1);
    }
  }
}
int DFS(int u, int t, int w) {
  if (u == t && w) {
    return w;
  }
  used[u] = 1;
  int res = 0;
  for (auto& v : G[u]) {
    if (!used[v.first]) {
      res = DFS(v.first, t, W2[v.first] + w + v.second);
      if (res) return res;
    }
  }
  return res;
}
int doDFS(int u, int t) {
  used[u] = 1;
  int res = W2[u];
  for (auto& v : G[u]) {
    if (!used[v.first]) {
      res |= DFS(v.first, t, W2[v.first] + v.second);
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  for (int n, m, u, v, a, b, w; cin >> n >> m;) {
    G.assign(n, vector<pair<int, int> >());
    edges.assign(m, 1);
    W.assign(m, 0);
    for (int i = 0; i < m; i++) {
      cin >> u >> v >> w;
      u--;
      v--;
      G[u].push_back(make_pair((v), (i)));
      G[v].push_back(make_pair((u), (i)));
      W[i] = w;
    }
    cin >> a >> b;
    init(G, n);
    W2.assign(cnt, 0);
    G1.assign(cnt, vector<pair<int, int> >());
    for (u = 0; u < G.size(); u++) {
      for (auto& ii : G[u]) {
        v = ii.first;
        w = ii.second;
        if (id[u] == id[v]) {
          W2[id[u]] |= W[w];
        } else {
          G1[id[u]].push_back(make_pair((id[v]), (W[w])));
          G1[id[v]].push_back(make_pair((id[u]), (W[w])));
        }
      }
    }
    a = id[a - 1];
    b = id[b - 1];
    G = G1;
    used.assign(cnt, 0);
    int res = doDFS(a, b);
    if (res) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
