#include <bits/stdc++.h>   using namespace std;   void read(long long &x) {     x = 0;     char c = getchar();     long long f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     x *= f;     return;   }   void print(long long x) {     if (x < 10) {       putchar(x +  0 );       return;     }     print(x / 10);     putchar(x % 10 +  0 );   }   void write(long long x) {     if (x < 0) x = -x, putchar( - );     print(x);   }   long long maxt(long long a, long long b) { return a < b ? b : a; }   long long mint(long long a, long long b) { return a < b ? a : b; }   struct node {     long long v, id;     node(long long V, long long Id) { v = V, id = Id; }   };   stack<long long> q, r;   vector<node> R[1000005], G[1000005];   vector<long long> E[1000005];   long long n, m, dfn[1000005], low[1000005], cnt, w[1000005], s[1000005],       bel[1000005], f[1000005], e[1000005], dep[1000005], col;   void tarjan(long long u, long long fa) {     q.push(u);     dfn[u] = low[u] = ++cnt;     for (int i = 0; i < R[u].size(); i++) {       long long v = R[u][i].v, id = R[u][i].id;       if (v == fa) continue;       r.push(id);       if (!dfn[v]) {         tarjan(v, u);         low[u] = mint(low[u], low[v]);         if (low[v] > dfn[u]) {           ++col;           while (r.top() != id) {             if (w[r.top()]) s[col] = 1;             r.pop();           }           r.pop();           while (q.top() != v) {             bel[q.top()] = col;             E[col].push_back(q.top());             q.pop();           }           bel[v] = col;           E[col].push_back(v);           q.pop();         }       } else         low[u] = mint(low[u], dfn[v]);     }     if (fa == -1) {       ++col;       while (!r.empty()) {         if (w[r.top()]) s[col] = 1;         r.pop();       }       while (!q.empty()) {         bel[q.top()] = col;         E[col].push_back(q.top());         q.pop();       }     }   }   void dfs(long long u, long long fa) {     f[u] = fa;     dep[u] = dep[fa] + 1;     for (int i = 0; i < G[u].size(); i++) {       long long v = G[u][i].v, id = G[u][i].id;       if (v == fa) continue;       e[v] = id;       dfs(v, u);     }   }   int main() {     read(n), read(m);     for (int i = 1; i <= m; i++) {       long long u, v;       read(u), read(v), read(w[i]);       R[u].push_back(node(v, i));       R[v].push_back(node(u, i));     }     for (int i = 1; i <= n; i++)       if (!dfn[i]) tarjan(i, -1);     for (int i = 1; i <= col; i++)       for (int j = 0; j < E[i].size(); j++) {         long long u = E[i][j];         for (int k = 0; k < R[u].size(); k++) {           long long v = R[u][k].v, id = R[u][k].id;           if (bel[u] != bel[v]) G[bel[u]].push_back(node(bel[v], id));         }       }     dfs(1, 1);     long long a, b;     bool fl = 0;     read(a), read(b);     a = bel[a], b = bel[b];     if (dep[a] < dep[b]) swap(a, b);     while (dep[a] > dep[b]) {       if (w[e[a]] || s[a]) fl = 1;       a = f[a];     }     while (a != b) {       if (w[e[a]] || w[e[b]] || s[a] || s[b]) fl = 1;       a = f[a];       b = f[b];     }     if (s[a]) fl = 1;     if (fl)       puts( YES );     else       puts( NO );   }