#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-6;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
  os << to_string(p.first) << " " << to_string(p.second);
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (ll i = (0); i < (ll)(v.size()); i++) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
struct modint {
  ll n;

 public:
  modint(const ll n = 0) : n((n % mod + mod) % mod) {}
  static modint pow(modint a, int m) {
    modint r = 1;
    while (m > 0) {
      if (m & 1) {
        r *= a;
      }
      a = (a * a);
      m /= 2;
    }
    return r;
  }
  modint& operator++() {
    *this += 1;
    return *this;
  }
  modint& operator--() {
    *this -= 1;
    return *this;
  }
  modint operator++(int) {
    modint ret = *this;
    *this += 1;
    return ret;
  }
  modint operator--(int) {
    modint ret = *this;
    *this -= 1;
    return ret;
  }
  modint operator~() const { return (this->pow(n, mod - 2)); }
  friend bool operator==(const modint& lhs, const modint& rhs) {
    return lhs.n == rhs.n;
  }
  friend bool operator<(const modint& lhs, const modint& rhs) {
    return lhs.n < rhs.n;
  }
  friend bool operator>(const modint& lhs, const modint& rhs) {
    return lhs.n > rhs.n;
  }
  friend modint& operator+=(modint& lhs, const modint& rhs) {
    lhs.n += rhs.n;
    if (lhs.n >= mod) lhs.n -= mod;
    return lhs;
  }
  friend modint& operator-=(modint& lhs, const modint& rhs) {
    lhs.n -= rhs.n;
    if (lhs.n < 0) lhs.n += mod;
    return lhs;
  }
  friend modint& operator*=(modint& lhs, const modint& rhs) {
    lhs.n = (lhs.n * rhs.n) % mod;
    return lhs;
  }
  friend modint& operator/=(modint& lhs, const modint& rhs) {
    lhs.n = (lhs.n * (~rhs).n) % mod;
    return lhs;
  }
  friend modint operator+(const modint& lhs, const modint& rhs) {
    return modint(lhs.n + rhs.n);
  }
  friend modint operator-(const modint& lhs, const modint& rhs) {
    return modint(lhs.n - rhs.n);
  }
  friend modint operator*(const modint& lhs, const modint& rhs) {
    return modint(lhs.n * rhs.n);
  }
  friend modint operator/(const modint& lhs, const modint& rhs) {
    return modint(lhs.n * (~rhs).n);
  }
};
istream& operator>>(istream& is, modint m) {
  is >> m.n;
  return is;
}
ostream& operator<<(ostream& os, modint m) {
  os << m.n;
  return os;
}
long long extgcd(long long a, long long b, long long& x, long long& y) {
  long long d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
long long mod_inverse(long long a, long long m) {
  long long x, y;
  if (extgcd(a, m, x, y) == 1)
    return (m + x % m) % m;
  else
    return -1;
}
vector<long long> fact(1010101 + 1, inf);
long long mod_fact(long long n, long long& e) {
  if (fact[0] == inf) {
    fact[0] = 1;
    if (1010101 != 0) fact[1] = 1;
    for (ll i = 2; i <= 1010101; ++i) {
      fact[i] = (fact[i - 1] * i) % mod;
    }
  }
  e = 0;
  if (n == 0) return 1;
  long long res = mod_fact(n / mod, e);
  e += n / mod;
  if ((n / mod) % 2 != 0) return (res * (mod - fact[n % mod])) % mod;
  return (res * fact[n % mod]) % mod;
}
long long mod_comb(long long n, long long k) {
  if (n < 0 || k < 0 || n < k) return 0;
  long long e1, e2, e3;
  long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2),
            a3 = mod_fact(n - k, e3);
  if (e1 > e2 + e3) return 0;
  return (a1 * mod_inverse((a2 * a3) % mod, mod)) % mod;
}
using mi = modint;
mi mod_pow(mi a, ll n) {
  mi ret = 1;
  mi tmp = a;
  while (n > 0) {
    if (n % 2) ret *= tmp;
    tmp = tmp * tmp;
    n /= 2;
  }
  return ret;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
using ld = long double;
template <typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge& operator=(const int& x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;
template <typename G>
struct LowLink {
  const G& g;
  vector<int> used, ord, low;
  vector<int> articulation;
  vector<pair<int, int>> bridge;
  LowLink(const G& g) : g(g) {}
  int dfs(int idx, int k, int par) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0;
    for (auto& to : g[idx]) {
      if (!used[to]) {
        ++cnt;
        k = dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= ~par && low[to] >= ord[idx];
        if (ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int)to));
      } else if (to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if (is_articulation) articulation.push_back(idx);
    return k;
  }
  virtual void build() {
    used.assign(g.size(), 0);
    ord.assign(g.size(), 0);
    low.assign(g.size(), 0);
    int k = 0;
    for (int i = 0; i < g.size(); i++) {
      if (!used[i]) k = dfs(i, k, -1);
    }
  }
};
template <typename G>
struct TwoEdgeConnectedComponents : LowLink<G> {
  using LL = LowLink<G>;
  vector<int> comp;
  TwoEdgeConnectedComponents(const G& g) : LL(g) {}
  int operator[](const int& k) { return comp[k]; }
  void dfs(int idx, int par, int& k) {
    if (~par && this->ord[par] >= this->low[idx])
      comp[idx] = comp[par];
    else
      comp[idx] = k++;
    for (auto& to : this->g[idx]) {
      if (comp[to] == -1) dfs(to, idx, k);
    }
  }
  void build(UnWeightedGraph& t) {
    LL::build();
    comp.assign(this->g.size(), -1);
    int k = 0;
    for (int i = 0; i < comp.size(); i++) {
      if (comp[i] == -1) dfs(i, -1, k);
    }
    t.resize(k);
    for (auto& e : this->bridge) {
      int x = comp[e.first], y = comp[e.second];
      t[x].push_back(y);
      t[y].push_back(x);
    }
  }
};
UnWeightedGraph g, buff;
int nn;
vector<bool> hasArtifact;
set<pair<int, int>> hasBridgeArtifact;
pair<bool, bool> dfs(int v, int par, int b) {
  pair<bool, bool> ret = {false, false};
  for (auto adj : buff[v]) {
    if (adj == par) continue;
    auto tmp = dfs(adj, v, b);
    ret.first = ret.first | tmp.first;
    ret.second = ret.second | tmp.second;
  }
  if (v == b) ret.first = true;
  if (ret.first && hasArtifact[v]) ret.second = true;
  if (ret.first && hasBridgeArtifact.count({v, par})) ret.second = true;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  g.resize(n);
  vector<pair<int, int>> artifact;
  for (ll i = (0); i < (ll)(m); i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
    if (w == 1) artifact.push_back({u, v});
  }
  int a, b;
  cin >> a >> b;
  a--;
  b--;
  TwoEdgeConnectedComponents<UnWeightedGraph> tecc(g);
  tecc.build(buff);
  nn = buff.size();
  hasArtifact.assign(nn, false);
  a = tecc[a];
  b = tecc[b];
  for (auto [u, v] : artifact) {
    if (tecc[u] == tecc[v])
      hasArtifact[tecc[u]] = true;
    else {
      hasBridgeArtifact.insert({tecc[u], tecc[v]});
      hasBridgeArtifact.insert({tecc[v], tecc[u]});
    }
  }
  auto [tmp, isYes] = dfs(a, -1, b);
  if (isYes)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

### Prompt

In CPP, your task is to solve the following problem:

Johnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience.

In that country there are n islands and m bridges between them, so you can travel from any island to any other. In the middle of some bridges are lying ancient powerful artifacts. Johnny is not interested in artifacts, but he can get some money by selling some artifact.

At the start Johnny is in the island a and the artifact-dealer is in the island b (possibly they are on the same island). Johnny wants to find some artifact, come to the dealer and sell it. The only difficulty is that bridges are too old and destroying right after passing over them. Johnnie's character can't swim, fly and teleport, so the problem became too difficult.

Note that Johnny can't pass the half of the bridge, collect the artifact and return to the same island. 

Determine if Johnny can find some artifact and sell it.

Input

The first line contains two integers n and m (1 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of islands and bridges in the game.

Each of the next m lines contains the description of the bridge — three integers xi, yi, zi (1 ≤ xi, yi ≤ n, xi ≠ yi, 0 ≤ zi ≤ 1), where xi and yi are the islands connected by the i-th bridge, zi equals to one if that bridge contains an artifact and to zero otherwise. There are no more than one bridge between any pair of islands. It is guaranteed that it's possible to travel between any pair of islands.

The last line contains two integers a and b (1 ≤ a, b ≤ n) — the islands where are Johnny and the artifact-dealer respectively.

Output

If Johnny can find some artifact and sell it print the only word "YES" (without quotes). Otherwise print the word "NO" (without quotes).

Examples

Input

6 7
1 2 0
2 3 0
3 1 0
3 4 1
4 5 0
5 6 0
6 4 0
1 6


Output

YES


Input

5 4
1 2 0
2 3 0
3 4 0
2 5 1
1 4


Output

NO


Input

5 6
1 2 0
2 3 0
3 1 0
3 4 0
4 5 1
5 3 0
1 2


Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-6;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
  os << to_string(p.first) << " " << to_string(p.second);
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (ll i = (0); i < (ll)(v.size()); i++) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
struct modint {
  ll n;

 public:
  modint(const ll n = 0) : n((n % mod + mod) % mod) {}
  static modint pow(modint a, int m) {
    modint r = 1;
    while (m > 0) {
      if (m & 1) {
        r *= a;
      }
      a = (a * a);
      m /= 2;
    }
    return r;
  }
  modint& operator++() {
    *this += 1;
    return *this;
  }
  modint& operator--() {
    *this -= 1;
    return *this;
  }
  modint operator++(int) {
    modint ret = *this;
    *this += 1;
    return ret;
  }
  modint operator--(int) {
    modint ret = *this;
    *this -= 1;
    return ret;
  }
  modint operator~() const { return (this->pow(n, mod - 2)); }
  friend bool operator==(const modint& lhs, const modint& rhs) {
    return lhs.n == rhs.n;
  }
  friend bool operator<(const modint& lhs, const modint& rhs) {
    return lhs.n < rhs.n;
  }
  friend bool operator>(const modint& lhs, const modint& rhs) {
    return lhs.n > rhs.n;
  }
  friend modint& operator+=(modint& lhs, const modint& rhs) {
    lhs.n += rhs.n;
    if (lhs.n >= mod) lhs.n -= mod;
    return lhs;
  }
  friend modint& operator-=(modint& lhs, const modint& rhs) {
    lhs.n -= rhs.n;
    if (lhs.n < 0) lhs.n += mod;
    return lhs;
  }
  friend modint& operator*=(modint& lhs, const modint& rhs) {
    lhs.n = (lhs.n * rhs.n) % mod;
    return lhs;
  }
  friend modint& operator/=(modint& lhs, const modint& rhs) {
    lhs.n = (lhs.n * (~rhs).n) % mod;
    return lhs;
  }
  friend modint operator+(const modint& lhs, const modint& rhs) {
    return modint(lhs.n + rhs.n);
  }
  friend modint operator-(const modint& lhs, const modint& rhs) {
    return modint(lhs.n - rhs.n);
  }
  friend modint operator*(const modint& lhs, const modint& rhs) {
    return modint(lhs.n * rhs.n);
  }
  friend modint operator/(const modint& lhs, const modint& rhs) {
    return modint(lhs.n * (~rhs).n);
  }
};
istream& operator>>(istream& is, modint m) {
  is >> m.n;
  return is;
}
ostream& operator<<(ostream& os, modint m) {
  os << m.n;
  return os;
}
long long extgcd(long long a, long long b, long long& x, long long& y) {
  long long d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
long long mod_inverse(long long a, long long m) {
  long long x, y;
  if (extgcd(a, m, x, y) == 1)
    return (m + x % m) % m;
  else
    return -1;
}
vector<long long> fact(1010101 + 1, inf);
long long mod_fact(long long n, long long& e) {
  if (fact[0] == inf) {
    fact[0] = 1;
    if (1010101 != 0) fact[1] = 1;
    for (ll i = 2; i <= 1010101; ++i) {
      fact[i] = (fact[i - 1] * i) % mod;
    }
  }
  e = 0;
  if (n == 0) return 1;
  long long res = mod_fact(n / mod, e);
  e += n / mod;
  if ((n / mod) % 2 != 0) return (res * (mod - fact[n % mod])) % mod;
  return (res * fact[n % mod]) % mod;
}
long long mod_comb(long long n, long long k) {
  if (n < 0 || k < 0 || n < k) return 0;
  long long e1, e2, e3;
  long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2),
            a3 = mod_fact(n - k, e3);
  if (e1 > e2 + e3) return 0;
  return (a1 * mod_inverse((a2 * a3) % mod, mod)) % mod;
}
using mi = modint;
mi mod_pow(mi a, ll n) {
  mi ret = 1;
  mi tmp = a;
  while (n > 0) {
    if (n % 2) ret *= tmp;
    tmp = tmp * tmp;
    n /= 2;
  }
  return ret;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
using ld = long double;
template <typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge& operator=(const int& x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;
template <typename G>
struct LowLink {
  const G& g;
  vector<int> used, ord, low;
  vector<int> articulation;
  vector<pair<int, int>> bridge;
  LowLink(const G& g) : g(g) {}
  int dfs(int idx, int k, int par) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0;
    for (auto& to : g[idx]) {
      if (!used[to]) {
        ++cnt;
        k = dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= ~par && low[to] >= ord[idx];
        if (ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int)to));
      } else if (to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if (is_articulation) articulation.push_back(idx);
    return k;
  }
  virtual void build() {
    used.assign(g.size(), 0);
    ord.assign(g.size(), 0);
    low.assign(g.size(), 0);
    int k = 0;
    for (int i = 0; i < g.size(); i++) {
      if (!used[i]) k = dfs(i, k, -1);
    }
  }
};
template <typename G>
struct TwoEdgeConnectedComponents : LowLink<G> {
  using LL = LowLink<G>;
  vector<int> comp;
  TwoEdgeConnectedComponents(const G& g) : LL(g) {}
  int operator[](const int& k) { return comp[k]; }
  void dfs(int idx, int par, int& k) {
    if (~par && this->ord[par] >= this->low[idx])
      comp[idx] = comp[par];
    else
      comp[idx] = k++;
    for (auto& to : this->g[idx]) {
      if (comp[to] == -1) dfs(to, idx, k);
    }
  }
  void build(UnWeightedGraph& t) {
    LL::build();
    comp.assign(this->g.size(), -1);
    int k = 0;
    for (int i = 0; i < comp.size(); i++) {
      if (comp[i] == -1) dfs(i, -1, k);
    }
    t.resize(k);
    for (auto& e : this->bridge) {
      int x = comp[e.first], y = comp[e.second];
      t[x].push_back(y);
      t[y].push_back(x);
    }
  }
};
UnWeightedGraph g, buff;
int nn;
vector<bool> hasArtifact;
set<pair<int, int>> hasBridgeArtifact;
pair<bool, bool> dfs(int v, int par, int b) {
  pair<bool, bool> ret = {false, false};
  for (auto adj : buff[v]) {
    if (adj == par) continue;
    auto tmp = dfs(adj, v, b);
    ret.first = ret.first | tmp.first;
    ret.second = ret.second | tmp.second;
  }
  if (v == b) ret.first = true;
  if (ret.first && hasArtifact[v]) ret.second = true;
  if (ret.first && hasBridgeArtifact.count({v, par})) ret.second = true;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  g.resize(n);
  vector<pair<int, int>> artifact;
  for (ll i = (0); i < (ll)(m); i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
    if (w == 1) artifact.push_back({u, v});
  }
  int a, b;
  cin >> a >> b;
  a--;
  b--;
  TwoEdgeConnectedComponents<UnWeightedGraph> tecc(g);
  tecc.build(buff);
  nn = buff.size();
  hasArtifact.assign(nn, false);
  a = tecc[a];
  b = tecc[b];
  for (auto [u, v] : artifact) {
    if (tecc[u] == tecc[v])
      hasArtifact[tecc[u]] = true;
    else {
      hasBridgeArtifact.insert({tecc[u], tecc[v]});
      hasBridgeArtifact.insert({tecc[v], tecc[u]});
    }
  }
  auto [tmp, isYes] = dfs(a, -1, b);
  if (isYes)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```