#include <bits/stdc++.h>
using namespace std;
class BCCBridgeGraph {
 public:
  BCCBridgeGraph(int num_vertices) : num_vertices_(num_vertices) {
    discovery_time_.resize(num_vertices + 1);
    low_link_.resize(num_vertices + 1);
    edges_.resize(num_vertices + 1);
    what_component_.resize(num_vertices + 1);
  }
  void AddEdge(int to, int from) {
    edges_[to].push_back(from);
    edges_[from].push_back(to);
  }
  void FindBiconnectedComponents() {
    current_count_ = 0;
    fill(discovery_time_.begin(), discovery_time_.end(), 0);
    fill(low_link_.begin(), low_link_.end(), 0);
    fill(what_component_.begin(), what_component_.end(), 0);
    biconnected_components_.clear();
    stack_.clear();
    Dfs(1, 0);
  }
  vector<vector<int>> GetBiconnectedComponents() {
    return biconnected_components_;
  }
  int GetComponent(int node) { return what_component_[node]; }

 private:
  void Dfs(int node, int father) {
    discovery_time_[node] = low_link_[node] = ++current_count_;
    stack_.push_back(node);
    for (auto neighbour : edges_[node]) {
      if (neighbour != father) {
        if (!discovery_time_[neighbour]) {
          Dfs(neighbour, node);
          low_link_[node] = min(low_link_[node], low_link_[neighbour]);
        } else {
          low_link_[node] = min(low_link_[node], discovery_time_[neighbour]);
        }
      }
    }
    if (low_link_[node] == discovery_time_[node]) {
      FetchComponent(node);
    }
  }
  void FetchComponent(int node) {
    vector<int> new_component;
    int components_size = (int)biconnected_components_.size() + 1;
    while (stack_.back() != node) {
      new_component.push_back(stack_.back());
      what_component_[stack_.back()] = components_size;
      stack_.pop_back();
    }
    stack_.pop_back();
    new_component.push_back(node);
    what_component_[node] = components_size;
    biconnected_components_.push_back(new_component);
  }
  const int num_vertices_;
  int current_count_;
  vector<int> discovery_time_;
  vector<int> low_link_;
  vector<int> what_component_;
  vector<vector<int>> edges_;
  vector<vector<int>> biconnected_components_;
  vector<int> stack_;
};
int main() {
  cin.sync_with_stdio(false);
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(m);
  vector<int> b(m);
  vector<int> c(m);
  BCCBridgeGraph graph(n);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    graph.AddEdge(a[i], b[i]);
  }
  int start, finish;
  scanf("%d%d", &start, &finish);
  graph.FindBiconnectedComponents();
  vector<int> good(n + 1);
  vector<vector<pair<int, int>>> v(n + 1);
  for (int i = 0; i < m; i++) {
    int a_component = graph.GetComponent(a[i]);
    int b_component = graph.GetComponent(b[i]);
    if (a_component != b_component) {
      v[a_component].push_back(make_pair(b_component, c[i]));
      v[b_component].push_back(make_pair(a_component, c[i]));
    } else if (c[i]) {
      good[a_component] = 1;
    }
  }
  start = graph.GetComponent(start);
  finish = graph.GetComponent(finish);
  function<void(int, int, int)> DfsOnBccTree = [&](int x, int f, int ok) {
    ok |= good[x];
    if (x == finish) {
      printf("%s\n", ok ? "YES" : "NO");
      exit(0);
    }
    for (auto it : v[x])
      if (it.first != f) DfsOnBccTree(it.first, x, ok || it.second);
  };
  DfsOnBccTree(start, 0, 0);
  return 0;
}
