#include <stdio.h>
#include <string.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N=300000+5;
const int M=300000+5;
struct EDGE
{
    int v, next, c;
}edge[M << 1];
int first[N], low[N], dfn[N], belong[N], sta[M], instack[M], num[N];
int g,cnt,top,scc;
int min(int a,int b)
{
    return a<b?a:b;
}
void AddEdge(int u,int v, int c)
{
    edge[g].v = v;
    edge[g].c = c;
    edge[g].next = first[u];
    first[u] = g++;
}
void Tarjan(int u,int fa)
{
    int v;
    low[u] = dfn[u] = ++cnt;
    sta[++top] = u;
    instack[u] = 1;
    for(int i = first[u]; i != -1; i = edge[i].next)
    {
        v = edge[i].v;
        if(i == (fa^1))
            continue;
        if(!dfn[v])
        {
            Tarjan(v,i);
            low[u] = min(low[u],low[v]);
        }
        else if(instack[v])
            low[u] = min(low[u],dfn[v]);
    }
    if(dfn[u] == low[u])
    {
        scc++;
        while(1)
        {
            v=sta[top--];
            instack[v] = 0;
            belong[v] = scc;
            if(v == u)
                break;
        }
    }
}
int vis[N];
vector <pair<int, int> >G[N];
int Bfs(int be, int en)
{
    queue<pair<int, int> > Q;
    while(!Q.empty()) Q.pop();
    memset(vis, 0, sizeof(vis));
    Q.push(make_pair(be, num[be]));
    vis[be] = 1;
    while(!Q.empty())
    {
        pair<int, int> now = Q.front();
        Q.pop();
        if(now.first == en) return now.second;
        int siz = G[now.first].size();
        for(int i = 0; i < siz; i++)
        {
            int next = G[now.first][i].first;
            if(vis[next]) continue;
            vis[next] = 1;
            Q.push(make_pair(next, now.second + num[next] + G[now.first][i].second));
        }
    }
}

int main()
{
    int n, m, target = 0, be, en;
    scanf("%d%d",&n,&m);
    g = cnt = top = scc = 0;
    memset(first, -1, sizeof(first));
    memset(low, 0, sizeof(low));
    memset(dfn, 0, sizeof(dfn));
    memset(num, 0, sizeof(num));
    memset(instack, 0, sizeof(instack));
    for(int u, v, c, i = 0; i < m; i++)
    {
        scanf("%d%d%d",&u,&v,&c);
        AddEdge(u, v, c);
        AddEdge(v, u, c);
        target += c;
    }
    for(int i = 1; i <= n; i++)
        if(!dfn[i])
            Tarjan(1,-1);
    for(int i = 1; i <= n; i++)
    {
        for(int j = first[i]; j != -1; j=edge[j].next)
        {
            int v = edge[j].v;
            if(belong[i] != belong[v])
            {
                G[belong[i]].push_back(make_pair(belong[v], edge[j].c));
            }
            else
                num[belong[i]] += edge[j].c;
        }
    }
    for(int i = 1; i <= scc; i++) num[i] /= 2;
    scanf("%d%d", &be, &en);
    if(Bfs(belong[be], belong[en])) puts("YES");
    else
        puts("NO");
}
/*
12 11
1 10 0
5 10 0
8 10 0
6 5 0
9 10 1
3 6 1
12 6 0
4 8 0
7 9 1
2 4 1
11 9 1
7 2
*/


#include <stdio.h>
#include <string.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N=300000+5;
const int M=300000+5;
struct EDGE
{
    int v, next, c;
}edge[M << 1];
int first[N], low[N], dfn[N], belong[N], sta[M], instack[M], num[N];
int g,cnt,top,scc;
int min(int a,int b)
{
    return a<b?a:b;
}
void AddEdge(int u,int v, int c)
{
    edge[g].v = v;
    edge[g].c = c;
    edge[g].next = first[u];
    first[u] = g++;
}
void Tarjan(int u,int fa)
{
    int v;
    low[u] = dfn[u] = ++cnt;
    sta[++top] = u;
    instack[u] = 1;
    for(int i = first[u]; i != -1; i = edge[i].next)
    {
        v = edge[i].v;
        if(i == (fa^1))
            continue;
        if(!dfn[v])
        {
            Tarjan(v,i);
            low[u] = min(low[u],low[v]);
        }
        else if(instack[v])
            low[u] = min(low[u],dfn[v]);
    }
    if(dfn[u] == low[u])
    {
        scc++;
        while(1)
        {
            v=sta[top--];
            instack[v] = 0;
            belong[v] = scc;
            if(v == u)
                break;
        }
    }
}
int vis[N];
vector <pair<int, int> >G[N];
int Bfs(int be, int en)
{
    queue<pair<int, int> > Q;
    while(!Q.empty()) Q.pop();
    memset(vis, 0, sizeof(vis));
    Q.push(make_pair(be, num[be]));
    vis[be] = 1;
    while(!Q.empty())
    {
        pair<int, int> now = Q.front();
        Q.pop();
        if(now.first == en) return now.second;
        int siz = G[now.first].size();
        for(int i = 0; i < siz; i++)
        {
            int next = G[now.first][i].first;
            if(vis[next]) continue;
            vis[next] = 1;
            Q.push(make_pair(next, now.second + num[next] + G[now.first][i].second));
        }
    }
}

int main()
{
    int n, m, target = 0, be, en;
    scanf("%d%d",&n,&m);
    g = cnt = top = scc = 0;
    memset(first, -1, sizeof(first));
    memset(low, 0, sizeof(low));
    memset(dfn, 0, sizeof(dfn));
    memset(num, 0, sizeof(num));
    memset(instack, 0, sizeof(instack));
    for(int u, v, c, i = 0; i < m; i++)
    {
        scanf("%d%d%d",&u,&v,&c);
        AddEdge(u, v, c);
        AddEdge(v, u, c);
        target += c;
    }
    for(int i = 1; i <= n; i++)
        if(!dfn[i])
            Tarjan(1,-1);
    for(int i = 1; i <= n; i++)
    {
        for(int j = first[i]; j != -1; j=edge[j].next)
        {
            int v = edge[j].v;
            if(belong[i] != belong[v])
            {
                G[belong[i]].push_back(make_pair(belong[v], edge[j].c));
            }
            else
                num[belong[i]] += edge[j].c;
        }
    }
    for(int i = 1; i <= scc; i++) num[i] /= 2;
    scanf("%d%d", &be, &en);
    if(Bfs(belong[be], belong[en]) == target && target) puts("YES");
    else
        puts("NO");
}


#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,m,u,v,w,s,t,stk[300100],top,dfn[300100],low[300100],clk;
bool flag[300100],ans;
struct edge
{
    int v;
    bool flag;
    edge *nxt;
} pool[600100],*tp=pool,*fst[300100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

bool dfs(int x,int fa)
{
    bool ret=x==t;
    dfn[stk[++top]=x]=low[x]=++clk;
    for (edge *i=fst[x]; i; i=i->nxt)
        if (i->v!=fa)
        {
            if (!dfn[i->v])
            {
                bool t=dfs(i->v,x);
                ret|=t;
                if (t || low[i->v]<=dfn[x])
                    flag[x]|=i->flag;
            }
            else
                flag[x]|=i->flag;
            low[x]=min(low[x],low[i->v]);
        }
    if (low[x]==dfn[x])
    {
        bool bol=0;
        for (int i=top; stk[i+1]!=x; bol|=flag[stk[i--]]);
        for (; stk[top+1]!=x; flag[stk[top--]]|=bol);
    }
    ans|=ret && flag[x];
    return ret;
}

int main()
{
    scanf("%d%d",&n,&m);
    while (m--)
    {
        u=getint(),v=getint(),w=getint();
        *tp=(edge){v,w,fst[u]},fst[u]=tp++;
        *tp=(edge){u,w,fst[v]},fst[v]=tp++;
    }
    scanf("%d%d",&s,&t),dfs(s,0);
    puts(ans?"YES":"NO");
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 3e5+10, M = N*2, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
int x, y, z;
int first[N], id;
int w[M], tp[M], nxt[M];
int dfn[N], low[N], tim;
int sta[N], top; bool e[N];
int c[N], color;
int v[N];
int ST, ED;
vector< pair<int,int> >a[N];
void ins(int x, int y, int z)
{
    w[++id] = y;
    nxt[id] = first[x];
    tp[id] = z;
    first[x] = id;
}
void tarjan(int x, int lastz)
{
    dfn[x] = low[x] = ++tim;
    sta[++top] = x; e[x] = 1;
    for (int z = first[x]; z; z = nxt[z])
    {
        if ((z^lastz) == 1)continue;
        int y = w[z];
        if (dfn[y] == 0)tarjan(y, z);
        if (e[y])gmin(low[x], low[y]);
    }
    if (dfn[x] == low[x])
    {
        v[++color] = 0;
        a[color].clear();
        while (1)
        {
            int y = sta[top--]; e[y] = 0;
            c[y] = color;
            if (y == x)break;
        }
    }
}
bool bfs()
{
    MS(e, 0);
    queue<int>q;
    q.push(c[ST]); e[c[ST]] = 1;
    while (!q.empty())
    {
        int x = q.front(); q.pop();
        for (int i = a[x].size() - 1; ~i; --i)
        {
            int y = a[x][i].first;
            int tp = a[x][i].second;
            if (e[y])continue;  //一定注意，我们只可以更新未入队的点
            v[y] |= v[x];

            q.push(y);
            e[y] = 1;
        }
    }
    return v[c[ED]];
}
bool solve()
{
    for (int x = 1; x <= n; ++x)
    {
        for (int z = first[x]; z; z = nxt[z])
        {
            int y = w[z];
            if (c[x] == c[y])v[c[x]] |= tp[z];
            a[c[x]].push_back(MP(c[y], tp[z]));
        }
    }
    if (c[ST] == c[ED] && v[c[ST]])return 1;
    return bfs();
}
int main()
{
    while (~scanf("%d%d", &n,&m))
    {
        MS(first, 0); id = 1;
        for (int i = 1; i <= m; ++i)
        {
            scanf("%d%d%d", &x, &y, &z);
            ins(x, y, z);
            ins(y, x, z);
        }
        scanf("%d%d", &ST, &ED);
        MS(dfn, 0); tim = color = 0;
        tarjan(1, 0);
        puts(solve() ? "YES" : "NO");
    }
    return 0;
}


#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
VPII e[SIZE];
int a,b,d[SIZE],No,bk[SIZE],dp[SIZE];
void dfs(int x,int lt){
    d[x]=bk[x]=++No;
    if(x==b)dp[x]|=2;
    bool good=0;
    REP(i,SZ(e[x])){
        int y=e[x][i].F;
        int v=e[x][i].S;
        if(y==lt)continue;
        if(d[y]){
            bk[x]=min(bk[x],d[y]);
            if(v)dp[x]|=1;
        }
        else{
            dfs(y,x);
            if(bk[y]<=d[x]){
                if(v)dp[x]|=1;
                dp[x]|=dp[y];
                bk[x]=min(bk[x],bk[y]);
            }
            if(dp[y]>=2)good=1;
            if(v&&dp[y]>=2)dp[x]|=1;
        }
    }
    if(good)dp[x]|=2;
    if(dp[x]==3){
        puts("YES");
        exit(0);
    }
}
int main(){
    DRII(n,m);
    REP(i,m){
        DRIII(x,y,v);
        e[x].PB(MP(y,v));
        e[y].PB(MP(x,v));
    }
    RII(a,b);
    dfs(a,a);
    puts("NO");
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
const int MAXN = 3e5 + 10;
typedef pair <int , int> P;
struct data {
    int next , to , art;
}edge[MAXN * 2];
int head[MAXN] , low[MAXN] , dfn[MAXN] , st[MAXN] , block[MAXN] , p[MAXN];
int top , ord , sccnum , end_point , cont;
bool instack[MAXN] , vis[MAXN] , ok , res;
vector <P> G[MAXN];

void init() {
    memset(head , -1 , sizeof(head));
}

inline void add(int u , int v , int art) {
    edge[cont].next = head[u];
    edge[cont].to = v;
    edge[cont].art = art;
    head[u] = cont++;
}

void tarjan(int u , int par) {
    low[u] = dfn[u] = ++ord;
    st[++top] = u;
    instack[u] = true;
    for(int i = head[u] ; ~i ; i = edge[i].next) {
        int v = edge[i].to;
        if(v == par)
            continue;
        if(!dfn[v]) {
            tarjan(v , u);
            low[u] = min(low[v] , low[u]);
        }
        else if(instack[v]) {
            low[u] = min(low[u] , dfn[v]);
        }
    }
    if(dfn[u] == low[u]) {
        sccnum++;
        int v;
        do {
            v = st[top--];
            instack[v] = false;
            block[v] = sccnum;
        }while(u != v);
    }
}

void dfs(int u , int par) {
    p[u] = par;
    for(int i = 0 ; i < G[u].size() ; i++) {
        int v = G[u][i].first;
        if(par == v)
            continue;
        if(G[u][i].second)
            vis[v] = true;
        dfs(v , u);
    }
}

int main()
{
    int n , m , u , v , art , s , e , heheda = 1;
    scanf("%d %d" , &n , &m);
    init();
    for(int i = 0 ; i < m ; i++) {
        scanf("%d %d %d" , &u , &v , &art);
        add(u , v , art);
        add(v , u , art);
        if(art == 1)
            heheda = 0;
    }
    scanf("%d %d" , &s , &e);
    if(heheda) {
        printf("NO\n");
        return 0;
    }
    tarjan(1 , -1);
    end_point = block[e];
    for(int u = 1 ; u <= n ; u++) {
        for(int i = head[u] ; ~i ; i = edge[i].next) {
            int v = edge[i].to;
            if(block[u] != block[v]) {
                G[block[u]].push_back(P(block[v] , edge[i].art));
            }
            else {
                if(!vis[block[u]])
                    vis[block[u]] = (bool)(edge[i].art);
            }
        }
    }
    if(block[s] == end_point && vis[block[s]]) {
        printf("YES\n");
        return 0;
    }
    if(vis[block[s]])
        res = true;
    dfs(block[s] , -1);
    for(int i = end_point ; ~i ; i = p[i]) {
        if(vis[i])
            res = true;
    }
    if(res)
        printf("YES\n");
    else
        printf("NO\n");
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

typedef long long ll;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)

//#define _MSC_VER 1
int n,m,a,b;
struct node{
	int to;
	int art;
	node(int i,int j)
	{to=i;art=j;}
};
list<node> g[300009];
list<ipair> connect[300009];
int disc[300009];
int low[300009];
bool visited[300009];
bool in[300009];
stack<int> s;
int block[300009];
int tim=0;
int cnt=0;
void tarjan(int i,int par)
{
	tim++;
	disc[i]=tim;
	low[i]=tim;
	visited[i]=true;
	s.push(i);
	list<node>::iterator j;
	for(j=g[i].begin();j!=g[i].end();j++)
	{
		int v=j->to;
		if(v==par)
			continue;
		if(disc[v]==0)
		{
			tarjan(v,i);
			low[i]=min(low[i],low[v]);

		}
		else
			if(visited[v])
				low[i]=min(low[i],disc[v]);
	}

	if(disc[i]==low[i])
	{
		cnt++;
		while(true)
		{
			int temp=s.top();
			s.pop();
			block[temp]=cnt;
			visited[temp]=false;
			if(temp==i)
				return;
		}

	}

}

bool sf[300009];
bool bfs()
{
	queue<int> q;
	q.push(block[a]);sf[block[a]]=true;
	while(!q.empty())
	{
		int temp=q.front();
		q.pop();
		list<ipair>::iterator ite;
		for(ite=connect[temp].begin();ite!=connect[temp].end();ite++)
		{
			int v=ite->first;
			int ar=ite->second;
			if(sf[v])
				continue;
			in[v]|=in[temp]|ar;
			q.push(v);
			sf[v]=true;
		}
	}
	if(in[block[b]])
		return true;
	else
		return false;

}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d",&n,&m);
//	cin>>n>>m;
	bool flag=false;
	cnt=0;
	for(int i=0;i<m;i++)
	{
		int temp1,temp2,temp3;
		scanf("%d%d%d",&temp1,&temp2,&temp3);
//		cin>>temp1>>temp2>>temp3;
		g[temp1].push_back(node(temp2,temp3));
		g[temp2].push_back(node(temp1,temp3));
		if(temp3)
			flag=true;
	}
	scanf("%d%d",&a,&b);
//	cin>>a>>b;
	if(!flag)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	tarjan(1,0);

	for(int i=1;i<=n;i++)
	{
		list<node>::iterator ite;
		for(ite=g[i].begin();ite!=g[i].end();ite++)
		{
			int v=ite->to;
			int art=ite->art;
			if(block[i]==block[v])
			{
				if(art==1)
					in[block[i]]=true;
			}
			else
			{
				connect[block[i]].push_back(MP(block[v],art));

			}

		}
	}
	if(block[a]==block[b]&&in[block[a]])
	{
		cout<<"YES"<<endl;
		return 0;

	}

	if(bfs())
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

typedef long long ll;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)

//#define _MSC_VER 1
int n,m,a,b;
struct node{
	int to;
	int art;
	node(int i,int j)
	{to=i;art=j;}
};
list<node> g[300009];
list<ipair> connect[300009];
int disc[300009];
int low[300009];
bool visited[300009];
bool in[300009];
stack<int> s;
int block[300009];
int tim=0;
int cnt=0;
void tarjan(int i,int par)
{
	tim++;
	disc[i]=tim;
	low[i]=tim;
	visited[i]=true;
	s.push(i);
	list<node>::iterator j;
	for(j=g[i].begin();j!=g[i].end();j++)
	{
		int v=j->to;
		if(v==par)
			continue;
		if(disc[v]==0)
		{
			tarjan(v,i);
			low[i]=min(low[i],low[v]);

		}
		else
			if(visited[v])
				low[i]=min(low[i],disc[v]);
	}

	if(disc[i]==low[i])
	{
		cnt++;
		while(true)
		{
			int temp=s.top();
			s.pop();
			block[temp]=cnt;
			visited[temp]=false;
			if(temp==i)
				return;
		}

	}

}

bool sf[300009];
bool bfs()
{
	queue<int> q;
	q.push(block[a]);sf[block[a]]=true;
	while(!q.empty())
	{
		int temp=q.front();
		q.pop();
		list<ipair>::iterator ite;
		for(ite=connect[temp].begin();ite!=connect[temp].end();ite++)
		{
			int v=ite->first;
			int ar=ite->second;
			if(sf[v])
				continue;
			in[v]|=in[temp]|ar;
			q.push(v);
			sf[v]=true;
		}
	}
	if(in[block[b]])
		return true;
	else
		return false;

}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	cin>>n>>m;
	bool flag=false;
	cnt=0;
	for(int i=0;i<m;i++)
	{
		int temp1,temp2,temp3;

		cin>>temp1>>temp2>>temp3;
		g[temp1].push_back(node(temp2,temp3));
		g[temp2].push_back(node(temp1,temp3));
		if(temp3)
			flag=true;
	}
	cin>>a>>b;
	if(!flag)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	tarjan(1,0);

	for(int i=1;i<=n;i++)
	{
		list<node>::iterator ite;
		for(ite=g[i].begin();ite!=g[i].end();ite++)
		{
			int v=ite->to;
			int art=ite->art;
			if(block[i]==block[v])
			{
				if(art==1)
					in[block[i]]=true;
			}
			else
			{
				connect[block[i]].push_back(MP(block[v],art));

			}

		}
	}
	if(block[a]==block[b]&&in[block[a]])
	{
		cout<<"YES"<<endl;
		return 0;

	}

	if(bfs())
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 3e5+10, M = N*2, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
int x, y, z;
int first[N], id;
int w[M], tp[M], nxt[M];
int dfn[N], low[N], tim;
int sta[N], top; bool e[N];
int c[N], color;
int v[N];
int ST, ED;
vector< pair<int,int> >a[N];
void ins(int x, int y, int z)
{
    w[++id] = y;
    nxt[id] = first[x];
    tp[id] = z;
    first[x] = id;
}
void tarjan(int x, int lastz)
{
    dfn[x] = low[x] = ++tim;
    sta[++top] = x; e[x] = 1;
    for (int z = first[x]; z; z = nxt[z])
    {
        if ((z^lastz) == 1)continue;
        int y = w[z];
        if (dfn[y] == 0)tarjan(y, z);
        if (e[y])gmin(low[x], low[y]);
    }
    if (dfn[x] == low[x])
    {
        v[++color] = 0;
        a[color].clear();
        while (1)
        {
            int y = sta[top--]; e[y] = 0;
            c[y] = color;
            if (y == x)break;
        }
    }
}
bool bfs()
{
    MS(e, 0);
    queue<int>q;
    q.push(c[ST]); e[c[ST]] = 1;
    while (!q.empty())
    {
        int x = q.front(); q.pop();
        for (int i = a[x].size() - 1; ~i; --i)
        {
            int y = a[x][i].first;
            int tp = a[x][i].second;
            if (e[y])continue;  //一定注意，我们只可以更新未入队的点
            v[y] |= v[x];
            v[y] |= tp;
            q.push(y);
            e[y] = 1;
        }
    }
    return v[c[ED]];
}
bool solve()
{
    for (int x = 1; x <= n; ++x)
    {
        for (int z = first[x]; z; z = nxt[z])
        {
            int y = w[z];
            if (c[x] == c[y])v[c[x]] |= tp[z];
            a[c[x]].push_back(MP(c[y], tp[z]));
        }
    }
    if (c[ST] == c[ED] && v[c[ST]])return 1;
    return bfs();
}
int main()
{
    while (~scanf("%d%d", &n,&m))
    {
        MS(first, 0); id = 1;
        for (int i = 1; i <= m; ++i)
        {
            scanf("%d%d%d", &x, &y, &z);
            ins(x, y, z);
            ins(y, x, z);
        }
        scanf("%d%d", &ST, &ED);
        MS(dfn, 0); tim = color = 0;
        tarjan(1, 0);
        puts(solve() ? "YES" : "NO");
    }
    return 0;
}


//Copyright(c)2016 liuchenrui
#include<bits/stdc++.h>
using namespace std;
inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
struct Edge{
	int to,next;
	bool is;
}edge[1200010];
bool f[1200010];
int low[1200010],dfn[1200010],size,first[1200010];
int tot,insta[1200010];
int is[1200010],can[1200010],ned[1200010];
int sta[1200010],top;
int n,m,s,t;
void addedge(int x,int y){
	size++;
	edge[size].to=y;
	edge[size].next=first[x];
	first[x]=size;
}
void add(int x,int y){
	addedge(x,y),addedge(y,x);
}
void dfs(int now,int fa){
	dfn[now]=low[now]=++tot;
	insta[now]=1,sta[++top]=now;
	for(int u=first[now];u;u=edge[u].next){
		if(edge[u].to==fa)continue;
		if(!dfn[edge[u].to]){
			dfs(edge[u].to,now);
			low[now]=min(low[now],low[edge[u].to]);
		}
		else if(insta[edge[u].to]){
			low[now]=min(low[now],dfn[edge[u].to]);
		}
		if(low[edge[u].to]>dfn[now]){
			edge[u].is=1;
			edge[((u-1)^1)+1].is=1;
		}
	}
	if(low[now]==dfn[now]){
		int x=0;
		do{
			x=sta[top--];
			insta[x]=0;
		}while(x!=now);
	}
}
bool vis[300010];
void dfs2(int x){
	vis[x]=1;
	for(int u=first[x];u;u=edge[u].next){
		if(edge[u].is)continue;
		if(ned[u+1>>1])puts("YES"),exit(0);
		if(!vis[edge[u].to]){
			dfs2(edge[u].to);
		}
	}
}
int main(){
	splay(n),splay(m);
	for(int i=1;i<=m;i++){
		int x,y;splay(x),splay(y);
		add(x,y);splay(ned[i]);
	}
	splay(s),splay(t);
	add(s,++n),add(n,t);
	dfs(s,0);dfs2(s);
	puts("NO");
}


//Copyright(c)2016 liuchenrui
#include<bits/stdc++.h>
using namespace std;
inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
struct Edge{
	int to,next;
}edge[600010];
bool f[300010];
int low[300010],dfn[300010],size,first[300010];
int tot,insta[300010];
int is[300010],can[300010],ned[300010];
int sta[300010],top;
int n,m,s,t;
void addedge(int x,int y){
	size++;
	edge[size].to=y;
	edge[size].next=first[x];
	first[x]=size;
}
void add(int x,int y){
	addedge(x,y),addedge(y,x);
}
void dfs(int now,int fa){
	dfn[now]=low[now]=++tot;
	insta[now]=1,sta[++top]=now;
	for(int u=first[now];u;u=edge[u].next){
		if(edge[u].to==fa)continue;
		if(!dfn[edge[u].to]){
			dfs(edge[u].to,now);
			low[now]=min(low[now],low[edge[u].to]);
		}
		else if(insta[edge[u].to]){
			low[now]=min(low[now],dfn[edge[u].to]);
		}
		if(low[edge[u].to]>dfn[now]){
			is[u+1>>1]=1;
		}
	}
	if(low[now]==dfn[now]){
		int x=0;
		do{
			x=sta[top--];
			insta[x]=0;
		}while(x!=now);
	}
}
bool vis[300010];
void dfs2(int x){
	vis[x]=1;
	for(int u=first[x];u;u=edge[u].next){
		if(!vis[edge[u].to]){
			dfs2(edge[u].to);
		}
		can[u>>1]=1;
	}
}
int main(){
	splay(n),splay(m);
	for(int i=1;i<=m;i++){
		int x,y;splay(x),splay(y);
		add(x,y);
		splay(ned[i]);
	}
	splay(s),splay(t);
	add(s,++n),add(n,t);
	dfs2(s);
	dfs(s,0);
	for(int i=1;i<=m;i++){
		if(!can[i])continue;
		if(ned[i]&&!is[i])puts("YES"),exit(0);
	}
	puts("NO");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#define MAXN 600000+100
using namespace std;
struct Edge{
    int u,v,w,next;
} E[MAXN*2];
int n,m,ss,tt;
int edge_cnt=0;
int head[MAXN];
int dfn[MAXN],low[MAXN];
bool instack[MAXN];
int block[MAXN];
int clock=0;
vector<pair<int,int> > tree[MAXN];
queue<int> q;
int val[MAXN];
void addedge(int u,int v,int w) {
    E[edge_cnt].u=u;
    E[edge_cnt].v=v;
    E[edge_cnt].w=w;
    E[edge_cnt].next=head[u];
    head[u]=edge_cnt++;
}
stack<int> sta;
int block_cnt=0;
void tarjan(int u,int fa) {
    //cout<<"u:"<<u<<endl;
    dfn[u]=low[u]=++clock;
    instack[u]=true;
    sta.push(u);
    int flag=0;
    for(int i=head[u]; i!=-1; i=E[i].next) {
        int v=E[i].v;
        if(v==fa&&!flag) {
            flag=1;
            continue;
        }
        if(dfn[v]==0) {
            tarjan(v,u);
            low[u]=min(low[u],low[v]);
        } else if( instack[v]==true ) {
            low[u]=min(low[u],dfn[v]);
        }
    }
    if(low[u]==dfn[u]) {
        block_cnt++;
        while(1) {
            int now=sta.top();
            sta.pop();
            instack[now]=false;
            block[now]=block_cnt;
            if(now==u) break;
        }
    }
}
void buildtree() {
    for(int i=0; i<2*m; i++) {
        int u=E[i].u,v=E[i].v,w=E[i].w;
            //cout<<"u v w:"<<u<<" "<<v<<" "<<w<<endl;
            //cout<<"bu bv:"<<block[u]<<" "<<block[v]<<endl;
        if( block[ u ]!=block[ v ] ) {
            u=block[u]; v=block[v];
            tree[u].push_back(make_pair(v,w));
            tree[v].push_back(make_pair(u,w));
        }else{
            if(E[i].w==1){
                val[ block[u] ]=1;
            }
        }
    }
}
int dis[MAXN];
int vis[MAXN];
int bfs(int ss,int tt){
    //cout<<"ss tt:"<<ss<<" "<<tt<<endl;
    memset(dis,0,sizeof(dis));
    memset(vis,0,sizeof(vis));
    q.push(ss);
    dis[ss]=val[ss];
    vis[ss]=1;
    while(q.size()){
        int now=q.front();
        q.pop();
        for(int i=0;i<tree[now].size();i++){
            int v=tree[now][i].first;
            if(vis[v]==1) continue;
            q.push(v);
            vis[v]=true;
            if(dis[v]<dis[now]+tree[now][i].second+val[v]){
                dis[v]=dis[now]+tree[now][i].second+val[v];
            }
            if(v==tt) break;
        }
    }
    return dis[ tt ];
}
int main() {
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    for(int i=0; i<m; i++) {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        addedge(u,v,w);
        addedge(v,u,w);
    }
    scanf("%d%d",&ss,&tt);
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    memset(instack,false,sizeof(instack));
    for(int i=1; i<=n; i++) {
        if(dfn[i]==0) {
            tarjan(i,-1);
        }
    }
    buildtree();
    if(bfs(block[ss],block[tt])>=1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef pair <int,int> pii;

const int N = 3*1e5+500;

int n,m;
int a,b,c;

pii mp(int a,int b){
    return make_pair(min(a,b),max(a,b));
}

map < pair <int,int> ,int > forbid;
map < pair <int,int> ,int > tre;
vector <int> graf[N];
vector <int> komp[N];
vector <int> arte[N];
int low[N],dis[N],timer = 1,bio[N],ima[N],cnt = 1;

int dfs(int x,int last){
    if(dis[x] != 0) return dis[x];
    dis[x] = timer++;
    low[x] = dis[x];
    for(int i = 0;i<graf[x].size();i++){
        if(graf[x][i] == last) continue;
        int moze = int(dis[graf[x][i]] == 0);
        int t = dfs(graf[x][i],x);
        if(t > dis[x] && moze) forbid[mp(x,graf[x][i])] = 1;
        low[x] = min(low[x],t);
    }
    return low[x];
}

void dfs2(int x,int last){
    bio[x] = cnt;
    for(int i = 0;i<graf[x].size();i++){
        if(forbid.find(mp(x,graf[x][i])) != forbid.end()) continue;
        if(tre[mp(x,graf[x][i])]) ima[cnt] = 1;
        if(bio[graf[x][i]] != 0) continue;
        dfs2(graf[x][i],x);
    }
}

int didit = 0,start,end;

void dfs3(int x,int last,int im){
    if(x == bio[end] && !didit){
        if(im) printf("YES\n");
        else printf("NO\n");
        didit = 1;
    }
    for(int i = 0;i<komp[x].size();i++){
        if(komp[x][i] == last) continue;
        dfs3(komp[x][i],x,im|ima[komp[x][i]]|arte[x][i]);
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i = 0;i<m;i++){
        scanf("%d%d%d",&a,&b,&c);
        graf[a].push_back(b);
        graf[b].push_back(a);
        tre[mp(a,b)] = c;
    }
    dfs(1,-1);
    for(int i = 1;i<=n;i++){
        if(!bio[i]) {dfs2(i,-1);cnt++;}
    }
    for(map< pair <int,int> , int >::iterator i = forbid.begin();i!=forbid.end();i++){
        if(bio[i->first.first] == bio[i->first.second]) continue;
        komp[bio[i->first.first]].push_back(bio[i->first.second]);
        komp[bio[i->first.second]].push_back(bio[i->first.first]);
        arte[bio[i->first.first]].push_back(tre[mp(i->first.first,i->first.second)]);
        arte[bio[i->first.second]].push_back(tre[mp(i->first.first,i->first.second)]);
        //printf("%d <=> %d\n",bio[i->first.first],bio[i->first.second]);
    }
    scanf("%d %d",&start,&end);
    dfs3(bio[start],-1,ima[bio[start]]);
    if(!didit){
        printf("NO\n");
    }
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef pair <int,int> pii;

const int N = 3*1e5+500;

int n,m;
int a,b,c;

pii mp(int a,int b){
    return make_pair(min(a,b),max(a,b));
}

map < pair <int,int> ,int > forbid;
map < pair <int,int> ,int > tre;
vector <int> graf[N];
vector <int> komp[N];
vector <int> arte[N];
int low[N],dis[N],timer = 1,bio[N],ima[N],cnt = 1;

int dfs(int x,int last){
    if(dis[x] != 0) return dis[x];
    dis[x] = timer++;
    low[x] = dis[x];
    for(int i = 0;i<graf[x].size();i++){
        if(graf[x][i] == last) continue;
        int moze = int(dis[graf[x][i]] == 0);
        int t = dfs(graf[x][i],x);
        if(t > dis[x] && moze) forbid[mp(x,graf[x][i])] = 1;
        low[x] = min(low[x],t);
    }
    return low[x];
}

void dfs2(int x,int last){
    bio[x] = cnt;
    for(int i = 0;i<graf[x].size();i++){
        if(bio[graf[x][i]] != 0) continue;
        if(forbid.find(mp(x,graf[x][i])) != forbid.end()) continue;

        if(tre[mp(x,graf[x][i])]) ima[cnt] = 1;

        dfs2(graf[x][i],x);
    }
}

int didit = 0,start,end;

void dfs3(int x,int last,int im){
    //printf("%d\n",x);
    if(x == bio[end] && !didit){
        if(im) printf("YES\n");
        else printf("NO\n");
        didit = 1;
    }
    for(int i = 0;i<komp[x].size();i++){
        if(komp[x][i] == last) continue;
        dfs3(komp[x][i],x,im|ima[komp[x][i]]|arte[bio[komp[x][i]]][i]);
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i = 0;i<m;i++){
        scanf("%d%d%d",&a,&b,&c);
        graf[a].push_back(b);
        graf[b].push_back(a);
        tre[mp(a,b)] = c;
    }
    dfs(1,-1);
    for(int i = 1;i<=n;i++){
        if(!bio[i]) {dfs2(i,-1);cnt++;}
    }
    for(map< pair <int,int> , int >::iterator i = forbid.begin();i!=forbid.end();i++){
        if(bio[i->first.first] == bio[i->first.second]) continue;
        komp[bio[i->first.first]].push_back(bio[i->first.second]);
        komp[bio[i->first.second]].push_back(bio[i->first.first]);
        arte[bio[i->first.first]].push_back(tre[mp(i->first.first,i->first.second)]);
        arte[bio[i->first.second]].push_back(tre[mp(i->first.first,i->first.second)]);
        //printf("%d <=> %d\n",bio[i->first.first],bio[i->first.second]);
    }
    scanf("%d %d",&start,&end);
    dfs3(start,-1,ima[start]);
    if(!didit){
        printf("NO\n");
    }
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef pair <int,int> pii;

const int N = 3*1e5+500;

int n,m;
int a,b,c;

pii mp(int a,int b){
    return make_pair(min(a,b),max(a,b));
}

map < pair <int,int> ,int > forbid;
map < pair <int,int> ,int > tre;
vector <int> graf[N];
vector <int> komp[N];
vector <int> arte[N];
int low[N],dis[N],timer = 1,bio[N],ima[N],cnt = 1;

int dfs(int x,int last){
    if(dis[x] != 0) return dis[x];
    dis[x] = timer++;
    low[x] = dis[x];
    for(int i = 0;i<graf[x].size();i++){
        if(graf[x][i] == last) continue;
        int moze = int(dis[graf[x][i]] == 0);
        int t = dfs(graf[x][i],x);
        if(t > dis[x] && moze) forbid[mp(x,graf[x][i])] = 1;
        low[x] = min(low[x],t);
    }
    return low[x];
}

void dfs2(int x,int last){
    bio[x] = cnt;
    for(int i = 0;i<graf[x].size();i++){
        if(forbid.find(mp(x,graf[x][i])) != forbid.end()) continue;
        if(tre[mp(x,graf[x][i])]) ima[cnt] = 1;
        if(bio[graf[x][i]] != 0) continue;
        dfs2(graf[x][i],x);
    }
}

int didit = 0,start,end;

void dfs3(int x,int last,int im){
    if(x == bio[end] && !didit){
        if(im) printf("YES\n");
        else printf("NO\n");
        didit = 1;
    }
    for(int i = 0;i<komp[x].size();i++){
        if(komp[x][i] == last) continue;
        dfs3(komp[x][i],x,im|ima[komp[x][i]]|arte[bio[komp[x][i]]][i]);
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i = 0;i<m;i++){
        scanf("%d%d%d",&a,&b,&c);
        graf[a].push_back(b);
        graf[b].push_back(a);
        tre[mp(a,b)] = c;
    }
    dfs(1,-1);
    for(int i = 1;i<=n;i++){
        if(!bio[i]) {dfs2(i,-1);cnt++;}
    }
    for(map< pair <int,int> , int >::iterator i = forbid.begin();i!=forbid.end();i++){
        if(bio[i->first.first] == bio[i->first.second]) continue;
        komp[bio[i->first.first]].push_back(bio[i->first.second]);
        komp[bio[i->first.second]].push_back(bio[i->first.first]);
        arte[bio[i->first.first]].push_back(tre[mp(i->first.first,i->first.second)]);
        arte[bio[i->first.second]].push_back(tre[mp(i->first.first,i->first.second)]);
        //printf("%d <=> %d\n",bio[i->first.first],bio[i->first.second]);
    }
    scanf("%d %d",&start,&end);
    dfs3(bio[start],-1,ima[bio[start]]);
    if(!didit){
        printf("NO\n");
    }
}


#include <iostream>
#include <vector>

using namespace std;

const int limite=1000000;

int n,m;

vector<int> g[limite];
vector<int> a[limite];
int visto[limite];
int profundidad[limite];
int profant[limite];
int ancestro[limite];
int identificador[limite];
int hay[limite];

vector<pair<int,int> > gg[limite];

int computaidentificador(int u)
{
  int &idu=identificador[u];
  if (idu==0) return u;
  idu=computaidentificador(idu);
  return idu;
}

void unir(int u,int v)
{
  //cout<<"unir "<<u<<" "<<v<<endl;
  int idu=computaidentificador(u);
  int idv=computaidentificador(v);
  if (idu==idv) return;
  identificador[u]=v;
}

void genera(int u,int p,int prof)
{
  //cout<<"genera "<<u<<" "<<p<<" "<<prof<<endl;
  visto[u]=1;
  profundidad[u]=prof;
  vector<int> ar=g[u];
  vector<int> &nextar=a[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i];
    if (v!=p and not visto[v]) {
      nextar.push_back(v);
      genera(v,u,prof+1);
    }
  }
  //cout<<"genera "<<u<<" "<<profundidad[u]<<endl;
}

void juntar(int u,int id)
{
  if (visto[u]) return;
  visto[u]=1;
  unir(u,id);
  vector<int> &ar=a[u];
  for (int i=0;i<int(ar.size());i++)
    juntar(ar[i],id);
}

void unifica(int u,int p)
{
  {
    profant[u]=profundidad[u];
    vector<int> &ar=a[u];
    for (int i=0;i<int(ar.size());i++)
      unifica(ar[i],u);
  }
  {
    //cout<<"profantini "<<u<<" "<<profant[u]<<endl;
    vector<int> &ar=g[u];
    for (int i=0;i<int(ar.size());i++) {
      int v=ar[i];
      if (v!=p) {
	profant[u]=min(profant[u],profant[v]);
	if (profant[v]>profant[u]) juntar(v,v);
      }
    }
  }
  //cout<<u<<" "<<profant[u]<<endl;
}

void reset()
{
  for (int i=1;i<=n;i++)
    visto[i]=0;
}

int au[limite],av[limite],aa[limite];

void computaancestro(int u,int p)
{
  ancestro[u]=p;
  vector<pair<int,int> > &ar=gg[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    if (v!=p) {
      if (ar[i].second==1) hay[v]=1;
      computaancestro(v,u);
    }
  }
}

int busca(int u)
{
  if (hay[u]) return 1;
  if (ancestro[u]==0) return 0;
  return busca(ancestro[u]);
}

int uini,ufin;

int main()
{
  ios::sync_with_stdio(false);
  cin>>n>>m;
  for (int i=0;i<m;i++) {
    cin>>au[i]>>av[i]>>aa[i];
    g[au[i]].push_back(av[i]);
    g[av[i]].push_back(au[i]);
  }
  cin>>uini>>ufin;
  genera(1,0,0);
  reset();
  unifica(1,0);
  juntar(1,1);
  for (int i=0;i<m;i++) {
    int u=au[i];
    int v=av[i];
    int arti=aa[i];
    int idu=computaidentificador(u);
    int idv=computaidentificador(v);
    if (idu!=idv) {
      gg[idu].push_back(pair<int,int> (idv,arti));
      gg[idv].push_back(pair<int,int> (idu,arti));
      //cout<<"anyade "<<idu<<" "<<idv<<endl;
    } else if (arti) hay[idu]=1;
  }
  int idini=computaidentificador(uini);
  int idfin=computaidentificador(ufin);
  //cout<<"idini "<<idini<<" idfin "<<idfin<<endl;
  computaancestro(idini,0);
  int sol=busca(idfin);
  if (sol) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


#include <iostream>
#include <vector>

using namespace std;

const int limite=1000000;

int n,m;

vector<int> g[limite];
vector<int> a[limite];
int visto[limite];
int profundidad[limite];
int profant[limite];
int ancestro[limite];
int identificador[limite];
int hay[limite];

vector<pair<int,int> > gg[limite];

int computaidentificador(int u)
{
  int &idu=identificador[u];
  if (idu==0) return u;
  idu=computaidentificador(idu);
  return idu;
}

void unir(int u,int v)
{
  //cout<<"unir "<<u<<" "<<v<<endl;
  int idu=computaidentificador(u);
  int idv=computaidentificador(v);
  if (idu==idv) return;
  identificador[u]=v;
}

void genera(int u,int p,int prof)
{
  //cout<<"genera "<<u<<" "<<p<<" "<<prof<<endl;
  visto[u]=1;
  profundidad[u]=prof;
  vector<int> ar=g[u];
  vector<int> &nextar=a[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i];
    if (v!=p and not visto[v]) {
      nextar.push_back(v);
      genera(v,u,prof+1);
    }
  }
  //cout<<"genera "<<u<<" "<<profundidad[u]<<endl;
}

void juntar(int u,int id)
{
  if (visto[u]) return;
  visto[u]=1;
  unir(u,id);
  vector<int> &ar=a[u];
  for (int i=0;i<int(ar.size());i++)
    juntar(ar[i],id);
}

void unifica(int u,int p)
{
  {
    profant[u]=profundidad[u];
    vector<int> &ar=a[u];
    for (int i=0;i<int(ar.size());i++)
      unifica(ar[i],u);
  }
  {
    //cout<<"profantini "<<u<<" "<<profant[u]<<endl;
    vector<int> &ar=g[u];
    for (int i=0;i<int(ar.size());i++) {
      int v=ar[i];
      if (v!=p) {
	profant[u]=min(profant[u],profant[v]);
	if (profant[v]>profundidad[u]) juntar(v,v);
      }
    }
  }
  //cout<<u<<" "<<profant[u]<<endl;
}

void reset()
{
  for (int i=1;i<=n;i++)
    visto[i]=0;
}

int au[limite],av[limite],aa[limite];

void computaancestro(int u,int p)
{
  ancestro[u]=p;
  vector<pair<int,int> > &ar=gg[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    if (v!=p) {
      if (ar[i].second==1) hay[v]=1;
      computaancestro(v,u);
    }
  }
}

int busca(int u)
{
  if (hay[u]) return 1;
  if (ancestro[u]==0) return 0;
  return busca(ancestro[u]);
}

int uini,ufin;

int main()
{
  ios::sync_with_stdio(false);
  cin>>n>>m;
  for (int i=0;i<m;i++) {
    cin>>au[i]>>av[i]>>aa[i];
    g[au[i]].push_back(av[i]);
    g[av[i]].push_back(au[i]);
  }
  cin>>uini>>ufin;
  genera(1,0,0);
  reset();
  unifica(1,0);
  juntar(1,1);
  for (int i=0;i<m;i++) {
    int u=au[i];
    int v=av[i];
    int arti=aa[i];
    int idu=computaidentificador(u);
    int idv=computaidentificador(v);
    if (idu!=idv) {
      gg[idu].push_back(pair<int,int> (idv,arti));
      gg[idv].push_back(pair<int,int> (idu,arti));
      //cout<<"anyade "<<idu<<" "<<idv<<endl;
    } else if (arti) hay[idu]=1;
  }
  int idini=computaidentificador(uini);
  int idfin=computaidentificador(ufin);
  //cout<<"idini "<<idini<<" idfin "<<idfin<<endl;
  computaancestro(idini,0);
  int sol=busca(idfin);
  if (sol) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


#include <iostream>
#include <vector>

using namespace std;

const int limite=1000000;

int n,m;

vector<int> g[limite];
vector<int> a[limite];
int visto[limite];
int profundidad[limite];
int profant[limite];
int ancestro[limite];
int identificador[limite];
int hay[limite];

vector<pair<int,int> > gg[limite];

int computaidentificador(int u)
{
  int &idu=identificador[u];
  if (idu==0) return u;
  idu=computaidentificador(idu);
  return idu;
}

void unir(int u,int v)
{
  int idu=computaidentificador(u);
  int idv=computaidentificador(v);
  if (idu==idv) return;
  identificador[u]=v;
}

void genera(int u,int p,int prof)
{
  //cout<<"genera "<<u<<" "<<p<<" "<<prof<<endl;
  visto[u]=1;
  profundidad[u]=prof;
  vector<int> ar=g[u];
  vector<int> &nextar=a[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i];
    if (v!=p and not visto[v]) {
      nextar.push_back(v);
      genera(v,u,prof+1);
    }
  }
}

void juntar(int u,int id)
{
  if (visto[u]) return;
  visto[u]=1;
  unir(u,id);
  vector<int> &ar=a[u];
  for (int i=0;i<int(ar.size());i++)
    juntar(ar[i],id);
}

void unifica(int u,int p)
{
  {
    vector<int> &ar=a[u];
    for (int i=0;i<int(ar.size());i++)
      unifica(ar[i],u);
  }
  {
    profant[u]=profundidad[u];
    vector<int> &ar=g[u];
    for (int i=0;i<int(ar.size());i++) {
      int v=ar[i];
      if (v!=p) {
	profant[u]=min(profant[u],profant[v]);
	if (profant[v]>profant[u]) juntar(v,v);
      }
    }
  }
  //cout<<u<<" "<<profant[u]<<endl;
}

void reset()
{
  for (int i=1;i<=n;i++)
    visto[i]=0;
}

int au[limite],av[limite],aa[limite];

void computaancestro(int u,int p)
{
  ancestro[u]=p;
  vector<pair<int,int> > &ar=gg[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    if (v!=p) {
      if (ar[i].second==1) hay[v]=1;
      computaancestro(v,u);
    }
  }
}

int busca(int u)
{
  if (hay[u]) return 1;
  if (ancestro[u]==0) return 0;
  return busca(ancestro[u]);
}

int uini,ufin;

int main()
{
  ios::sync_with_stdio(false);
  cin>>n>>m;
  for (int i=0;i<m;i++) {
    cin>>au[i]>>av[i]>>aa[i];
    g[au[i]].push_back(av[i]);
    g[av[i]].push_back(au[i]);
  }
  cin>>uini>>ufin;
  genera(1,0,0);
  reset();
  unifica(1,0);
  juntar(1,1);
  for (int i=0;i<m;i++) {
    int u=au[i];
    int v=av[i];
    int arti=aa[i];
    int idu=computaidentificador(u);
    int idv=computaidentificador(v);
    if (idu!=idv) {
      gg[idu].push_back(pair<int,int> (idv,arti));
      gg[idv].push_back(pair<int,int> (idu,arti));
      //cout<<"anyade "<<idu<<" "<<idv<<endl;
    } else hay[idu]=1;
  }
  int idini=computaidentificador(uini);
  int idfin=computaidentificador(ufin);
  computaancestro(idini,0);
  int sol=busca(idfin);
  if (sol) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct Road{
	int e,next,tag,used;
}r[620000],r1[1300000];

int R[310000],R1[310000];
int low[310000],dfn[310000],ins[310000],sta[310000],bl[310000];
int have[310000],S,T,n,m,_,num=1,num1=1,top,piece,Index,ans;

void clear(){
	num=num1=1;top=piece=ans=0;
	memset(R,0,sizeof(R));
	memset(R1,0,sizeof(R1));
	memset(low,0,sizeof(low));
	memset(dfn,0,sizeof(dfn));
	memset(ins,0,sizeof(ins));
	memset(sta,0,sizeof(sta));
	memset(bl,0,sizeof(bl));
	memset(have,0,sizeof(have));
}

void addr1(int x,int y,int tag){
	++num1;
	r1[num1].e=y;
	r1[num1].tag=tag;
	r1[num1].next=R1[x];
	r1[num1].used=0;
	R1[x]=num1;
}

void addr(int x,int y,int tag){
	++num;
	r[num].e=y;
	r[num].tag=tag;
	r[num].next=R[x];
	r[num].used=0;
	R[x]=num;
}

void tarjan(int u){
	low[u]=dfn[u]=++Index;
	sta[++top]=u;ins[u]=1;
	for(int i=R[u];i;i=r[i].next){
		if(r[i].used)continue;
		r[i].used=r[i^1].used=1;
		int v=r[i].e;
		if(dfn[v]==0){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}else if(ins[v]==1){
			low[u]=min(low[u],dfn[v]);
		}
	}if(low[u]==dfn[u]){
		int now=-1;
		piece++;
		while(u!=now){
			now=sta[top--];
			ins[now]=0;
			bl[now]=piece;
		}
	}
}

void dfs(int now,int fa,int take){
	take|=have[now];
	if(now==bl[T])ans|=take;
	for(int i=R1[now];i;i=r1[i].next){
		int v=r1[i].e;
		if(v==fa)continue;
		dfs(v,now,take|r1[i].tag);
	}
}

int main(){
	int x,y,t;
	//scanf("%d",&_);
	_=1;
	while(_--){
		clear();
		scanf("%d %d",&n,&m);
		for(int i=1;i<=m;i++){
			scanf("%d %d %d",&x,&y,&t);
			addr(x,y,t);addr(y,x,t);
		}for(int i=1;i<=n;i++){
			if(dfn[i]==0)tarjan(i);
		}for(int i=1;i<=n;i++){
			for(int j=R[i];j;j=r[j].next){
				int u=i,v=r[j].e;
				if(bl[u]==bl[v]&&r[j].tag)have[bl[u]]=1;
				else if(bl[u]!=bl[v])addr1(bl[u],bl[v],r[j].tag),addr1(bl[v],bl[u],r[j].tag);
			}
		}scanf("%d %d",&S,&T);
		dfs(bl[S],0,0);
		printf("%s\n",ans?"YES":"NO");
	}return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct Road{
	int e,next,tag,used;
}r[620000],r1[1300000];

int R[310000],R1[310000];
int low[310000],dfn[310000],ins[310000],sta[310000],bl[310000];
int have[310000],S,T,n,m,_,num=1,num1=1,top,piece,Index,ans;

void clear(){
	num=num1=1;top=piece=ans=0;
	memset(R,0,sizeof(R));
	memset(R1,0,sizeof(R1));
	memset(low,0,sizeof(low));
	memset(dfn,0,sizeof(dfn));
	memset(ins,0,sizeof(ins));
	memset(sta,0,sizeof(sta));
	memset(bl,0,sizeof(bl));
	memset(have,0,sizeof(have));
}

void addr1(int x,int y,int tag){
	++num1;
	r1[num1].e=y;
	r1[num1].tag=tag;
	r1[num1].next=R1[x];
	r1[num1].used=0;
	R1[x]=num1;
}

void addr(int x,int y,int tag){
	++num;
	r[num].e=y;
	r[num].tag=tag;
	r[num].next=R[x];
	r[num].used=0;
	R[x]=num;
}

void tarjan(int u){
	low[u]=dfn[u]=++Index;
	sta[++top]=u;ins[u]=1;
	for(int i=R[u];i;i=r[i].next){
		if(r[i].used)continue;
		r[i].used=r[i^1].used=1;
		int v=r[i].e;
		if(dfn[v]==0){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}else if(ins[v]==1){
			low[u]=min(low[u],dfn[v]);
		}
	}if(low[u]==dfn[u]){
		int now=-1;
		piece++;
		while(u!=now){
			now=sta[top--];
			ins[now]=0;
			bl[now]=piece;
		}
	}
}

void dfs(int now,int fa,int take){
	take|=have[now];
	if(now==bl[T])ans|=take;
	for(int i=R1[now];i;i=r1[i].next){
		int v=r1[i].e;
		if(v==fa)continue;
		dfs(v,now,take|r1[i].tag);
	}
}

int main(){
	int x,y,t;
	scanf("%d",&_);
	while(_--){
		clear();
		scanf("%d %d",&n,&m);
		for(int i=1;i<=m;i++){
			scanf("%d %d %d",&x,&y,&t);
			addr(x,y,t);addr(y,x,t);
		}for(int i=1;i<=n;i++){
			if(dfn[i]==0)tarjan(i);
		}for(int i=1;i<=n;i++){
			for(int j=R[i];j;j=r[j].next){
				int u=i,v=r[j].e;
				if(bl[u]==bl[v]&&r[j].tag)have[bl[u]]=1;
				else if(bl[u]!=bl[v])addr1(bl[u],bl[v],r[j].tag),addr1(bl[v],bl[u],r[j].tag);
			}
		}scanf("%d %d",&S,&T);
		dfs(bl[S],0,0);
		printf("%s\n",ans?"YES":"NO");
	}return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct Road{
	int e,next,tag,used;
}r[620000],r1[1300000];

int R[310000],R1[310000];
int low[310000],dfn[310000],ins[310000],sta[310000],bl[310000];
int have[310000],S,T,n,m,_,num=1,num1=1,top,piece,Index,ans;

void clear(){
	num=num1=1;top=piece=ans=0;
	memset(R,0,sizeof(R));
	memset(R1,0,sizeof(R1));
	memset(low,0,sizeof(low));
	memset(dfn,0,sizeof(dfn));
	memset(ins,0,sizeof(ins));
	memset(sta,0,sizeof(sta));
	memset(bl,0,sizeof(bl));
	memset(have,0,sizeof(have));
}

void addr1(int x,int y,int tag){
	++num1;
	r1[num1].e=y;
	r1[num1].tag=tag;
	r1[num1].next=R1[x];
	r1[num1].used=0;
	R1[x]=num1;
}

void addr(int x,int y,int tag){
	++num;
	r[num].e=y;
	r[num].tag=tag;
	r[num].next=R[x];
	r[num].used=0;
	R[x]=num;
}

void tarjan(int u){
	low[u]=dfn[u]=++Index;
	sta[++top]=u;ins[u]=1;
	for(int i=R[u];i;i=r[i].next){
		if(r[i].used)continue;
		r[i].used=r[i^1].used=1;
		int v=r[i].e;
		if(dfn[v]==0){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}else if(ins[v]==1){
			low[u]=min(low[u],dfn[v]);
		}
	}if(low[u]==dfn[u]){
		int now=-1;
		piece++;
		while(u!=now){
			now=sta[top--];
			ins[now]=0;
			bl[now]=piece;
		}
	}
}

void dfs(int now,int fa,int take){
	take|=have[now];
	if(now==bl[T])ans|=take;
	for(int i=R1[now];i;i=r1[i].next){
		int v=r1[i].e;
		if(v==fa)continue;
		dfs(v,now,take|r1[i].tag);
	}
}

int main(){
	int x,y,t;
	 _=1;
	while(_--){
		clear();
		scanf("%d %d",&n,&m);
		for(int i=1;i<=m;i++){
			scanf("%d %d %d",&x,&y,&t);
			addr(x,y,t);addr(y,x,t);
		}for(int i=1;i<=n;i++){
			if(dfn[i]==0)tarjan(i);
		}for(int i=1;i<=n;i++){
			for(int j=R[i];j;j=r[j].next){
				int u=i,v=r[j].e;
				if(bl[u]==bl[v]&&r[j].tag)have[bl[u]]=1;
				else if(bl[u]!=bl[v])addr1(bl[u],bl[v],r[j].tag);
			}
		}scanf("%d %d",&S,&T);
		dfs(bl[S],0,0);
		printf("%s\n",ans?"YES":"NO");
	}return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct Road{
	int e,next,tag,used;
}r[620000],r1[1300000];

int R[310000],R1[310000];
int low[310000],dfn[310000],ins[310000],sta[310000],bl[310000];
int have[310000],S,T,n,m,_,num=1,num1=1,top,piece,Index,ans;

void clear(){
	num=num1=1;top=piece=ans=0;
	memset(R,0,sizeof(R));
	memset(R1,0,sizeof(R1));
	memset(low,0,sizeof(low));
	memset(dfn,0,sizeof(dfn));
	memset(ins,0,sizeof(ins));
	memset(sta,0,sizeof(sta));
	memset(bl,0,sizeof(bl));
	memset(have,0,sizeof(have));
}

void addr1(int x,int y,int tag){
	++num1;
	r1[num1].e=y;
	r1[num1].tag=tag;
	r1[num1].next=R1[x];
	r1[num1].used=0;
	R1[x]=num1;
}

void addr(int x,int y,int tag){
	++num;
	r[num].e=y;
	r[num].tag=tag;
	r[num].next=R[x];
	r[num].used=0;
	R[x]=num;
}

void tarjan(int u){
	low[u]=dfn[u]=++Index;
	sta[++top]=u;ins[u]=1;
	for(int i=R[u];i;i=r[i].next){
		if(r[i].used)continue;
		r[i].used=r[i^1].used=1;
		int v=r[i].e;
		if(dfn[v]==0){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}else if(ins[v]==1){
			low[u]=min(low[u],dfn[v]);
		}
	}if(low[u]==dfn[u]){
		int now=-1;
		piece++;
		while(u!=now){
			now=sta[top--];
			ins[now]=0;
			bl[now]=piece;
		}
	}
}

void dfs(int now,int fa,int take){
	take|=have[now];
	if(now==bl[T])ans|=take;
	for(int i=R1[now];i;i=r1[i].next){
		int v=r1[i].e;
		if(v==fa)continue;
		dfs(v,now,take|r1[i].tag);
	}
}

int main(){
	int x,y,t;
	scanf("%d",&_); _=1;
	while(_--){
		clear();
		scanf("%d %d",&n,&m);
		for(int i=1;i<=m;i++){
			scanf("%d %d %d",&x,&y,&t);
			addr(x,y,t);addr(y,x,t);
		}for(int i=1;i<=n;i++){
			if(dfn[i]==0)tarjan(i);
		}for(int i=1;i<=n;i++){
			for(int j=R[i];j;j=r[j].next){
				int u=i,v=r[j].e;
				if(bl[u]==bl[v]&&r[j].tag)have[bl[u]]=1;
				else if(bl[u]!=bl[v])addr1(bl[u],bl[v],r[j].tag);
			}
		}scanf("%d %d",&S,&T);
		dfs(bl[S],0,0);
		printf("%s\n",ans?"YES":"NO");
	}return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<ll>;
using pii = pair<ll,ll>;
#define FOR(i, a, b) for(ll i = (a); i < ll(b); i++)
#define sz(c) ll((c).size())
#define DBG if(0)

vi num, st;
vector<vector<pii>> ed;
ll Time;
template<class F>
ll dfs(ll at, ll par, F f) {
	ll me = num[at] = ++Time, e, y, top = me;
	for(auto &pa: ed[at]) if (pa.second != par) {
		tie(y, e) = pa;
		if (num[y]) {
			top = min(top, num[y]);
			if (num[y] < me)
				st.push_back(e);
		} else {
			ll si = sz(st);
			ll up = dfs(y, e, f);
			top = min(top, up);
			if (up == me) {
				st.push_back(e);
				f(vi(st.begin() + si, st.end()));
				st.resize(si);
			}
			else if (up < me)
				st.push_back(e);
			// else e is a bridge
            // else f({e});
		}
	}
	return top;
}

template<class F>
void bicomps(F f) {
	num.assign(sz(ed), 0);
	FOR(i,0,sz(ed)) if (!num[i]) dfs(i, -1, f);
}

ll C;
set<ll> comps[500005];
ll vertex[500005][2];
bool artifact[500005];
bool cartifact[500005];
ll realcomp[500005];
ll comp1[500005];
vector<pair<ll, bool>> adj[500005];
vector<pair<ll, bool>> cadj[500005];
ll dest;

ll rdfs(ll cur, ll par) {
    ll res = cartifact[cur] ? 1 : 0;
    if(cur == dest) return res | 2;
    for(auto &p: cadj[cur]) if(p.first != par) {
            ll dr = rdfs(p.first, cur);
            if(dr < 2) continue;
            return dr | res | p.second;
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    ll N, M;
    while(cin >> N >> M) {
        C = 0;
        ed.clear();
        memset(cartifact, 0, sizeof(cartifact));
        FOR(i, 0, N) {
            adj[i].clear(); cadj[i].clear();
        }
        ed.resize(N);
        ll eid = 0;
        FOR(i, 0, M) {
            ll a, b, z;
            cin >> a >> b >> z;
            a--; b--;
            vertex[eid][0] = a;
            vertex[eid][1] = b;
            adj[a].emplace_back(b, z);
            adj[b].emplace_back(a, z);
            artifact[eid] = z;
            ed[a].emplace_back(b, eid);
            ed[b].emplace_back(a, eid++);
        }
        FOR(i, 0, N) comps[i].clear();
        ll a;
        cin >> a >> dest;
        a--; dest--;

        bicomps([&](const vi& edges) {
                DBG cout << C << ": ";
                for(auto e: edges) {
                    DBG cout << vertex[e][0] << " -> " << vertex[e][1] << " ";
                    comps[vertex[e][0]].insert(C);
                    comps[vertex[e][1]].insert(C);
                }
                DBG cout << endl;
                C += 1;
            });

        FOR(i, 0, C) realcomp[i] = i;

        FOR(i, 0, N) {
            if(comps[i].size() > 1) {
                ll firstc = realcomp[*comps[i].begin()];
                for(auto c:comps[i]) {
                    realcomp[c] = firstc;
                }
            } else if(comps[i].size() == 0) {
                comps[i].insert(C);
                realcomp[C] = C;
                C += 1;
            }
        }
        FOR(i, 0, N) {
            DBG cout << i << ": ";
            DBG for(auto c: comps[i])
                cout << c << "&" << realcomp[c] << " ";
            DBG cout << endl;
            comp1[i] = realcomp[*comps[i].begin()];
        }

        FOR(i, 0, N) {
            for(auto &p:adj[i]) {
                if(comp1[p.first] == comp1[i]) {
                    cartifact[comp1[i]] |= p.second;
                } else {
                    cadj[comp1[i]].emplace_back(comp1[p.first], p.second);
                }
            }
        }

        dest = comp1[dest];
        if(rdfs(comp1[a], -1) & 1) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<ll>;
using pii = pair<ll,ll>;
#define FOR(i, a, b) for(ll i = (a); i < ll(b); i++)
#define sz(c) ll((c).size())
#define DBG if(0)

vi num, st;
vector<vi> adj, comps;
ll Time, C;
ll dfs(ll at, ll par) {
	ll me = num[at] = ++Time, top = me;
    st.push_back(at);
    bool first = true; // for detecting multi edges
	for(auto y: adj[at]) {
        if(y == par && first) { first = false; continue; }
		if (num[y]) {
			top = min(top, num[y]);
		} else {
			ll si = sz(st);
			ll up = dfs(y, at);
			top = min(top, up);
			if (up == me) { // (*) >= for bridge components
				FOR(p, si, sz(st)) comps[st[p]].push_back(C);
                comps[at].push_back(C++);
				st.resize(si);
			}
			if(up > me) { /*e is a bridge*/ }
		}
	}
	return top;
}

void bicomps() {
	num.assign(sz(adj), 0); C = 0;
    comps.clear(); comps.resize(sz(adj));
	FOR(i,0,sz(adj)) if (!num[i]) dfs(i, -1);
}

bool artifact[500005];
bool cartifact[500005];
ll uf[500005];
ll comp1[500005];
vector<pair<ll, bool>> adj2[500005];
vector<pair<ll, bool>> cadj[500005];
ll dest;

ll find(ll x) { return uf[x] < 0 ? x : uf[x] = find(uf[x]); }
void join(ll a, ll b) {
    a = find(a); b = find(b);
    if(a == b) return;
    if(uf[a] > uf[b]) swap(a, b);
    uf[a] += uf[b]; uf[b] = a;
}

ll rdfs(ll cur, ll par) {
    ll res = cartifact[cur] ? 1 : 0;
    if(cur == dest) return res | 2;
    for(auto &p: cadj[cur]) if(p.first != par) {
            ll dr = rdfs(p.first, cur);
            if(dr < 2) continue;
            return dr | res | p.second;
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    ll N, M;
    while(cin >> N >> M) {
        C = 0;
        memset(cartifact, 0, sizeof(cartifact));
        FOR(i, 0, N) {
            adj2[i].clear(); cadj[i].clear();
        }
        adj.clear();
        adj.resize(N);
        FOR(i, 0, M) {
            ll a, b, z;
            cin >> a >> b >> z;
            a--; b--;
            adj2[a].emplace_back(b, z);
            adj2[b].emplace_back(a, z);
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        ll a;
        cin >> a >> dest;
        a--; dest--;

        bicomps();

        memset(uf, -1, sizeof(uf));

        FOR(i, 0, N) {
            assert(set<ll>(comps[i].begin(), comps[i].end()).size() == sz(comps[i]));
            if(comps[i].size() > 1) {
                ll firstc = *comps[i].begin();
                for(auto c:comps[i]) {
                    join(firstc, c);
                }
            } else if(comps[i].size() == 0) {
                comps[i].push_back(C);
                C += 1;
            }
        }
        FOR(i, 0, N) {
            comp1[i] = find(*comps[i].begin());
            //for(auto c: comps[i]) assert(realcomp[c] == comp1[i]);
        }

        FOR(i, 0, N) {
            for(auto &p:adj2[i]) {
                if(comp1[p.first] == comp1[i]) {
                    cartifact[comp1[i]] |= p.second;
                } else {
                    cadj[comp1[i]].emplace_back(comp1[p.first], p.second);
                }
            }
        }

        dest = comp1[dest];
        if(rdfs(comp1[a], -1) & 1) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<ll>;
using pii = pair<ll,ll>;
#define FOR(i, a, b) for(ll i = (a); i < ll(b); i++)
#define sz(c) ll((c).size())
#define DBG if(0)

vi num, st;
vector<vi> adj, comps;
ll Time, C;
ll dfs(ll at, ll par) {
	ll me = num[at] = ++Time, top = me;
    st.push_back(at);
    bool first = true; // for detecting multi edges
	for(auto y: adj[at]) {
        if(y == par && first) { first = false; continue; }
		if (num[y]) {
			top = min(top, num[y]);
		} else {
			ll si = sz(st);
			ll up = dfs(y, at);
			top = min(top, up);
			if (up >= me) { // (*) >= for bridge components
                if(up == me) {
                    FOR(p, si, sz(st)) comps[st[p]].push_back(C);
                    comps[at].push_back(C++);
                }
				st.resize(si);
			}
			if(up > me) { /*e is a bridge*/ }
		}
	}
	return top;
}

void bicomps() {
	num.assign(sz(adj), 0); C = 0;
    comps.clear(); comps.resize(sz(adj));
	FOR(i,0,sz(adj)) if (!num[i]) dfs(i, -1);
}

bool artifact[500005];
bool cartifact[500005];
ll uf[500005];
ll comp1[500005];
vector<pair<ll, bool>> adj2[500005];
vector<pair<ll, bool>> cadj[500005];
ll dest;

ll find(ll x) { return uf[x] < 0 ? x : uf[x] = find(uf[x]); }
void join(ll a, ll b) {
    a = find(a); b = find(b);
    if(a == b) return;
    if(uf[a] > uf[b]) swap(a, b);
    uf[a] += uf[b]; uf[b] = a;
}

ll rdfs(ll cur, ll par) {
    ll res = cartifact[cur] ? 1 : 0;
    if(cur == dest) return res | 2;
    for(auto &p: cadj[cur]) if(p.first != par) {
            ll dr = rdfs(p.first, cur);
            if(dr < 2) continue;
            return dr | res | p.second;
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    ll N, M;
    while(cin >> N >> M) {
        C = 0;
        memset(cartifact, 0, sizeof(cartifact));
        FOR(i, 0, N) {
            adj2[i].clear(); cadj[i].clear();
        }
        adj.clear();
        adj.resize(N);
        FOR(i, 0, M) {
            ll a, b, z;
            cin >> a >> b >> z;
            a--; b--;
            adj2[a].emplace_back(b, z);
            adj2[b].emplace_back(a, z);
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        ll a;
        cin >> a >> dest;
        a--; dest--;

        bicomps();

        memset(uf, -1, sizeof(uf));

        FOR(i, 0, N) {
            assert(set<ll>(comps[i].begin(), comps[i].end()).size() == sz(comps[i]));
            if(comps[i].size() > 1) {
                ll firstc = *comps[i].begin();
                for(auto c:comps[i]) {
                    join(firstc, c);
                }
            } else if(comps[i].size() == 0) {
                comps[i].push_back(C);
                C += 1;
            }
        }
        FOR(i, 0, N) {
            comp1[i] = find(*comps[i].begin());
            //for(auto c: comps[i]) assert(realcomp[c] == comp1[i]);
        }

        FOR(i, 0, N) {
            for(auto &p:adj2[i]) {
                if(comp1[p.first] == comp1[i]) {
                    cartifact[comp1[i]] |= p.second;
                } else {
                    cadj[comp1[i]].emplace_back(comp1[p.first], p.second);
                }
            }
        }

        dest = comp1[dest];
        if(rdfs(comp1[a], -1) & 1) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<ll>;
using pii = pair<ll,ll>;
#define FOR(i, a, b) for(ll i = (a); i < ll(b); i++)
#define sz(c) ll((c).size())
#define DBG if(0)

vi num, st;
vector<vector<pii>> ed;
ll Time;
template<class F>
ll dfs(ll at, ll par, F f) {
	ll me = num[at] = ++Time, e, y, top = me;
	for(auto &pa: ed[at]) if (pa.second != par) {
		tie(y, e) = pa;
		if (num[y]) {
			top = min(top, num[y]);
			if (num[y] < me)
				st.push_back(e);
		} else {
			ll si = sz(st);
			ll up = dfs(y, e, f);
			top = min(top, up);
			if (up == me) {
				st.push_back(e);
				f(vi(st.begin() + si, st.end()));
				st.resize(si);
			}
			else if (up < me)
				st.push_back(e);
			// else e is a bridge
            // else f({e});
		}
	}
	return top;
}

template<class F>
void bicomps(F f) {
	num.assign(sz(ed), 0);
	FOR(i,0,sz(ed)) if (!num[i]) dfs(i, -1, f);
}

ll C;
set<ll> comps[500005];
ll vertex[500005][2];
bool artifact[500005];
bool cartifact[500005];
ll uf[500005];
ll comp1[500005];
vector<pair<ll, bool>> adj[500005];
vector<pair<ll, bool>> cadj[500005];
ll dest;

ll find(ll x) { return uf[x] < 0 ? x : uf[x] = find(uf[x]); }
void join(ll a, ll b) {
    a = find(a); b = find(b);
    if(a == b) return;
    if(uf[a] > uf[b]) swap(a, b);
    uf[a] += uf[b]; uf[b] = a;
}

ll rdfs(ll cur, ll par) {
    ll res = cartifact[cur] ? 1 : 0;
    if(cur == dest) return res | 2;
    for(auto &p: cadj[cur]) if(p.first != par) {
            ll dr = rdfs(p.first, cur);
            if(dr < 2) continue;
            return dr | res | p.second;
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    ll N, M;
    while(cin >> N >> M) {
        C = 0;
        ed.clear();
        memset(cartifact, 0, sizeof(cartifact));
        FOR(i, 0, N) {
            adj[i].clear(); cadj[i].clear();
        }
        ed.resize(N);
        ll eid = 0;
        FOR(i, 0, M) {
            ll a, b, z;
            cin >> a >> b >> z;
            a--; b--;
            vertex[eid][0] = a;
            vertex[eid][1] = b;
            adj[a].emplace_back(b, z);
            adj[b].emplace_back(a, z);
            artifact[eid] = z;
            ed[a].emplace_back(b, eid);
            ed[b].emplace_back(a, eid++);
        }
        FOR(i, 0, N) comps[i].clear();
        ll a;
        cin >> a >> dest;
        a--; dest--;

        bicomps([&](const vi& edges) {
                DBG cout << C << ": ";
                for(auto e: edges) {
                    DBG cout << vertex[e][0] << " -> " << vertex[e][1] << " ";
                    comps[vertex[e][0]].insert(C);
                    comps[vertex[e][1]].insert(C);
                }
                DBG cout << endl;
                C += 1;
            });

        memset(uf, -1, sizeof(uf));

        FOR(i, 0, N) {
            if(comps[i].size() > 1) {
                ll firstc = *comps[i].begin();
                for(auto c:comps[i]) {
                    join(firstc, c);
                }
            } else if(comps[i].size() == 0) {
                comps[i].insert(C);
                C += 1;
            }
        }
        FOR(i, 0, N) {
            comp1[i] = find(*comps[i].begin());
            //for(auto c: comps[i]) assert(realcomp[c] == comp1[i]);
        }

        FOR(i, 0, N) {
            for(auto &p:adj[i]) {
                if(comp1[p.first] == comp1[i]) {
                    cartifact[comp1[i]] |= p.second;
                } else {
                    cadj[comp1[i]].emplace_back(comp1[p.first], p.second);
                }
            }
        }

        dest = comp1[dest];
        if(rdfs(comp1[a], -1) & 1) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n; // number of nodes
vector<vector<int> > graph(300005);
vector<vector<int> > bigraph(300005); // adjacency list of graph
vector<bool> visited;
vector<int> tin, low;
int timer;
map<pair<int,int>,bool>brig;
map<pair<int,int>,bool >brig1;
map<pair<int,int>,bool>artifacts;
vector<vector<int> >bridges(300005);
int me;
int dealer;

void IS_BRIDGE(int a,int b){
  bridges[a].push_back(b);
  bridges[b].push_back(a);
  brig[make_pair(a,b)]=1;
  brig[make_pair(b,a)]=1;
}
void dfs(int v, int p = -1) {
    visited[v] = true;
    tin[v] = low[v] = timer++;
    for (int to : graph[v]) {
        if (to == p) continue;
        if (visited[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs(to, v);
            low[v] = min(low[v], low[to]);
            if (low[to] > tin[v])
                IS_BRIDGE(v, to);
        }
    }
}
vector<bool>containart(300005);
vector<int>bico(300005);
int color=0;
void dfs1(int v) {
    visited[v] = true;
    if(v==me)me=color;
    if(v==dealer)dealer=color;
    bico[v]=color;
     for (int to : graph[v]) {

         if(visited[to]==false&&brig[make_pair(v,to)]==0){
           dfs1(to);
         }
         else if(artifacts[make_pair(v,to)]==1&&bico[v]==bico[to])containart[color]=1;
        }

}
void dfs(){
  containart.assign(n,false);
  visited.assign(n,false);
  for(int i=0;i<n;i++){
    if(visited[i]==false){dfs1(i);
    color++;}
  }
}

void find_bridges() {
    timer = 0;
    visited.assign(n, false);
    tin.assign(n, -1);
    low.assign(n, -1);
    for (int i = 0; i < n; ++i) {
        if (!visited[i])
            dfs(i);
    }
}

int main(){
int m;
cin>>n>>m;
for(int i=0;i<m;i++){
  int t1,t2,t3;
  cin>>t1>>t2>>t3;
  t1--;t2--;
  graph[t1].push_back(t2);
  graph[t2].push_back(t1);

  if(t3==1){artifacts[make_pair(t1,t2)]=1;artifacts[make_pair(t2,t1)]=1;}
}
cin>>me>>dealer;
me--;
dealer--;
find_bridges();
dfs();
for(int i=0;i<n;i++){
for(int j: bridges[i]){
  if(bico[i]==bico[j])continue;
  else {
    //cout<<bico[i]<<" "<<bico[j]<<endl;
    bigraph[bico[i]].push_back(bico[j]);
    //bigraph[bico[j]].push_back(bico[i]);
brig1[make_pair(bico[i],bico[j])]=artifacts[make_pair(i,j)];
brig1[make_pair(bico[j],bico[i])]=artifacts[make_pair(i,j)];
  }
}
}
/*
for(int i=0;i<n;i++){
  for(int j:bigraph[i]){
    cout<<j<<" ";
  }
  cout<<containart[i+1]<<endl;
}
*/

stack<int>s;
visited.assign(color,false);
vector<int>parent(color);
s.push(me);
while(s.size()!=0){
int top=s.top();
visited[top]=true;
s.pop();
for(int i=0;i<bigraph[top].size();i++){
 if (visited[bigraph[top][i]]==false){
   parent[bigraph[top][i]]=top;
   s.push(bigraph[top][i]);
 }
}
}
//cout<<brig1[make_pair(0,1)]<<" "<<artifacts[make_pair(2,3)]<<endl;

//cout<<me<<" "<<dealer<<endl;

int t=-1;bool p=false;
if(containart[dealer]==true)p=true;
while(dealer!=me){
  //cout<<dealer<<endl;
t=parent[dealer];
if(containart[t]||brig1[make_pair(t,dealer)])p=true;
dealer=t;
}

if(p)cout<<"YES";
else cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
int n; // number of nodes
vector<vector<int> > graph(300005);
vector<vector<int> > bigraph(300005); // adjacency list of graph
vector<bool> visited;
vector<int> tin, low;
int timer;
map<pair<int,int>,bool>brig;
map<pair<int,int>,bool >brig1;
map<pair<int,int>,bool>artifacts;
vector<vector<int> >bridges(300005);
int me;
int dealer;

void IS_BRIDGE(int a,int b){
  bridges[a].push_back(b);
  bridges[b].push_back(a);
  brig[make_pair(a,b)]=1;
  brig[make_pair(b,a)]=1;
}
void dfs(int v, int p = -1) {
    visited[v] = true;
    tin[v] = low[v] = timer++;
    for (int to : graph[v]) {
        if (to == p) continue;
        if (visited[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs(to, v);
            low[v] = min(low[v], low[to]);
            if (low[to] > tin[v])
                IS_BRIDGE(v, to);
        }
    }
}
vector<bool>containart(300005);
vector<int>bico(300005);
int color=0;
void dfs1(int v) {
    visited[v] = true;
    if(v==me)me=color;
    if(v==dealer)dealer=color;
    bico[v]=color;
     for (int to : graph[v]) {

         if(visited[to]==false&&brig[make_pair(v,to)]==0){
           dfs1(to);
         }
         else if(artifacts[make_pair(v,to)]==1&&bico[v]==bico[to]&&brig[make_pair(v,to)]==0)containart[color]=1;
        }

}
void dfs(){
  containart.assign(n,false);
  visited.assign(n,false);
  for(int i=0;i<n;i++){
    if(visited[i]==false){dfs1(i);
    color++;}
  }
}

void find_bridges() {
    timer = 0;
    visited.assign(n, false);
    tin.assign(n, -1);
    low.assign(n, -1);
    for (int i = 0; i < n; ++i) {
        if (!visited[i])
            dfs(i);
    }
}

int main(){
int m;
cin>>n>>m;
for(int i=0;i<m;i++){
  int t1,t2,t3;
  cin>>t1>>t2>>t3;
  t1--;t2--;
  graph[t1].push_back(t2);
  graph[t2].push_back(t1);

  if(t3==1){artifacts[make_pair(t1,t2)]=1;artifacts[make_pair(t2,t1)]=1;}
}
cin>>me>>dealer;
me--;
dealer--;
find_bridges();
dfs();
for(int i=0;i<n;i++){
for(int j: bridges[i]){
  if(bico[i]==bico[j])continue;
  else {
    //cout<<bico[i]<<" "<<bico[j]<<endl;
    bigraph[bico[i]].push_back(bico[j]);
    //bigraph[bico[j]].push_back(bico[i]);
brig1[make_pair(bico[i],bico[j])]=artifacts[make_pair(i,j)];
brig1[make_pair(bico[j],bico[i])]=artifacts[make_pair(i,j)];
  }
}
}
/*
for(int i=0;i<n;i++){
  for(int j:bigraph[i]){
    cout<<j<<" ";
  }
  cout<<containart[i+1]<<endl;
}
*/

stack<int>s;
visited.assign(color,false);
vector<int>parent(color);
s.push(me);
while(s.size()!=0){
int top=s.top();
visited[top]=true;
s.pop();
for(int i=0;i<bigraph[top].size();i++){
 if (visited[bigraph[top][i]]==false){
   parent[bigraph[top][i]]=top;
   s.push(bigraph[top][i]);
 }
}
}
//cout<<brig1[make_pair(0,1)]<<" "<<artifacts[make_pair(2,3)]<<endl;

//cout<<me<<" "<<dealer<<endl;
//cout<<bigraph[0][0]<<" "<<bigraph[1][0]<<endl;
int t=-1;bool p=false;
if(containart[dealer]==true){p=true;}
while(dealer!=me){
  //cout<<dealer<<endl;
t=parent[dealer];
if(containart[t]||brig1[make_pair(t,dealer)])p=true;
dealer=t;
}

if(p)cout<<"YES";
else cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
int n; // number of nodes
vector<vector<int> > graph(300005);
vector<vector<int> > bigraph(300005); // adjacency list of graph
vector<bool> visited;
vector<int> tin, low;
int timer;
map<pair<int,int>,bool>brig;
map<pair<int,int>,bool >brig1;
map<pair<int,int>,bool>artifacts;
vector<vector<int> >bridges(300005);
int me;
int dealer;

void IS_BRIDGE(int a,int b){
  bridges[a].push_back(b);
  bridges[b].push_back(a);
  brig[make_pair(a,b)]=1;
  brig[make_pair(b,a)]=1;
}
void dfs(int v, int p = -1) {
    visited[v] = true;
    tin[v] = low[v] = timer++;
    for (int to : graph[v]) {
        if (to == p) continue;
        if (visited[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs(to, v);
            low[v] = min(low[v], low[to]);
            if (low[to] > tin[v])
                IS_BRIDGE(v, to);
        }
    }
}
vector<bool>containart(300005);
vector<int>bico(300005);
int color=0;
void dfs1(int v) {
    visited[v] = true;
    if(v==me)me=color;
    if(v==dealer)dealer=color;
    bico[v]=color;
     for (int to : graph[v]) {
         if(visited[to]==false&&brig[make_pair(v,to)]==0){
           if(artifacts[make_pair(v,to)]==1)containart[color]=1;
           dfs1(to);
         }
        }

}
void dfs(){
  containart.assign(n,false);
  visited.assign(n,false);
  for(int i=0;i<n;i++){
    if(visited[i]==false){dfs1(i);
    color++;}
  }
}

void find_bridges() {
    timer = 0;
    visited.assign(n, false);
    tin.assign(n, -1);
    low.assign(n, -1);
    for (int i = 0; i < n; ++i) {
        if (!visited[i])
            dfs(i);
    }
}

int main(){
int m;
cin>>n>>m;
for(int i=0;i<m;i++){
  int t1,t2,t3;
  cin>>t1>>t2>>t3;
  t1--;t2--;
  graph[t1].push_back(t2);
  graph[t2].push_back(t1);

  if(t3==1){artifacts[make_pair(t1,t2)]=1;artifacts[make_pair(t2,t1)]=1;}
}
cin>>me>>dealer;
me--;
dealer--;
find_bridges();
dfs();
for(int i=0;i<n;i++){
for(int j: bridges[i]){
  if(bico[i]==bico[j])continue;
  else {
    //cout<<bico[i]<<" "<<bico[j]<<endl;
    bigraph[bico[i]].push_back(bico[j]);
    //bigraph[bico[j]].push_back(bico[i]);
brig1[make_pair(bico[i],bico[j])]=artifacts[make_pair(i,j)];
brig1[make_pair(bico[j],bico[i])]=artifacts[make_pair(i,j)];
  }
}
}
/*
for(int i=0;i<n;i++){
  for(int j:bigraph[i]){
    cout<<j<<" ";
  }
  cout<<containart[i+1]<<endl;
}
*/

stack<int>s;
visited.assign(color,false);
vector<int>parent(color);
s.push(me);
while(s.size()!=0){
int top=s.top();
visited[top]=true;
s.pop();
for(int i=0;i<bigraph[top].size();i++){
 if (visited[bigraph[top][i]]==false){
   parent[bigraph[top][i]]=top;
   s.push(bigraph[top][i]);
 }
}
}
//cout<<brig1[make_pair(0,1)]<<" "<<artifacts[make_pair(2,3)]<<endl;

//cout<<me<<" "<<dealer<<endl;

int t=-1;bool p=false;
if(containart[dealer]==true)p=true;
while(dealer!=me){
  //cout<<dealer<<endl;
t=parent[dealer];
if(containart[t]||brig1[make_pair(t,dealer)])p=true;
dealer=t;
}

if(p)cout<<"YES";
else cout<<"NO";

}


#include <bits/stdc++.h>
using namespace std;
#define vi              vector <int>
#define vvi             vector < vi >
#define ii              pair < int,int >
#define vii             vector < ii >
#define all(v)          ((v).begin()), ((v).end())
#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(ll i=0;i<sz(v);++i)
#define lp(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb              push_back
#define MP              make_pair
#define READ            freopen("in.txt","r",stdin)
#define WRITE           freopen("output.txt","w",stdout)
#define scf(n)          scanf("%d",&n)
#define FastIO          ios_base::sync_with_stdio(false)
#define vb              vector <bool>
#define ull unsigned long long
#define REP0(i,n) for (int i = 0; i<n; i++)
#define REP(i,x,n) for (int i = x; i<n; i++)
#define REV0(i,n) for (int i = n - 1; i>=0; i--)
#define REV(i,x,n) for (int i = n - x - 1; i>=0; i--)

typedef long long ll;

vector< vector<int> > comToNode;
vector<int> nodeToCom;

vector<int> indx;               // order of each node in the DFS, initialized by -1
vector<int> lowLink;    // after runing the algorithm, it has a unique indx for each component, this indx is the minimum indx for the set of nodes in that component
stack<int> stk;                 // has the current nodes currently in the stack
int curIndex;
vector<vector<int> > adjList;   // the graph
vector<bool> inStack;   // 1 for nodes that are currently in the stack, 0 otherwise

void tarjanDFS(int i, int par) {
        lowLink[i] = indx[i] = curIndex++;
        stk.push(i);
        inStack[i] = 1;
        for(int j=0;j<adjList[i].size();j++) {
			if(indx[ adjList[i][j] ]==-1 && adjList[i][j]!=par) {
				tarjanDFS( adjList[i][j] ,i );
				lowLink[i] = min(lowLink[i],lowLink[ adjList[i][j] ]);
                }
			else if(inStack[ adjList[i][j] ] && adjList[i][j]!=par)
				lowLink[i] = min(lowLink[i],indx[ adjList[i][j] ]);
        }
        if(indx[i] == lowLink[i])       {
                vector<int> v;
                while(!stk.empty()) {
                        int ind = stk.top();
                        stk.pop();
                        v.push_back(ind);                       // updating the answer
                        nodeToCom[ind] = comToNode.size();
                        inStack[ind] = 0;
                        if(ind==i) break;
                }
                comToNode.push_back(v);

        }
}

void tarjanSCC(int n) { // call it in main

        indx = vector<int>(n,-1);
        lowLink = vector<int>(n,-1);
        nodeToCom = vector<int>(n,-1);
        comToNode = vector< vector<int> >();
        inStack = vector<bool>(n,0);
        stk = stack<int>();
        curIndex = 0;

        for(int i=0;i<adjList.size();i++)
                if(indx[i]==-1)
                        tarjanDFS(i,-1);
}
vector<pair<ii,int> > edge;
vector<vector<ii> > g;
vi x;
int s,t;
bool dfs(int u,int p,bool b){
    if(u==t)return b;
    lp(i,0,g[u].size()){
        int v=g[u][i].first;
        int c=g[u][i].second;
        if(p!=v){
            if(dfs(v,u,b||x[v]||c))return 1;
        }
    }
    return 0;
}
int main() {
#ifndef ONLINE_JUDGE
    READ;
#endif
    FastIO;
    int n,m;
    cin>>n>>m;
    adjList.resize(n);
    lp(i,0,m){
        int u,v,w;
        cin>>u>>v>>w;
        u--,v--;
        adjList[u].pb(v);
        adjList[v].pb(u);
        edge.pb(MP(MP(u,v),w));
    }
    cin>>s>>t;
    tarjanSCC(n);
    g.resize(comToNode.size());
    x.resize(comToNode.size(),0);
    lp(i,0,m){
        int a=nodeToCom[edge[i].first.first];
        int b=nodeToCom[edge[i].first.second];
        int c=edge[i].second;
        if(a==b){
            x[a]=(x[a]||c);
        }
        else{
            g[a].pb(MP(b,c));
            g[b].pb(MP(a,c));
        }
    }
    s--,t--;
    s=nodeToCom[s],t=nodeToCom[t];
    if(dfs(s,-1,x[s]))cout<<"YES";else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi              vector <int>
#define vvi             vector < vi >
#define ii              pair < int,int >
#define vii             vector < ii >
#define all(v)          ((v).begin()), ((v).end())
#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(ll i=0;i<sz(v);++i)
#define lp(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb              push_back
#define MP              make_pair
#define READ            freopen("in.txt","r",stdin)
#define WRITE           freopen("output.txt","w",stdout)
#define scf(n)          scanf("%d",&n)
#define FastIO          ios_base::sync_with_stdio(false)
#define vb              vector <bool>
#define ull unsigned long long
#define REP0(i,n) for (int i = 0; i<n; i++)
#define REP(i,x,n) for (int i = x; i<n; i++)
#define REV0(i,n) for (int i = n - 1; i>=0; i--)
#define REV(i,x,n) for (int i = n - x - 1; i>=0; i--)

typedef long long ll;

vector< vector<int> > comToNode;
vector<int> nodeToCom;

vector<int> indx;               // order of each node in the DFS, initialized by -1
vector<int> lowLink;    // after runing the algorithm, it has a unique indx for each component, this indx is the minimum indx for the set of nodes in that component
stack<int> stk;                 // has the current nodes currently in the stack
int curIndex;
vector<vector<int> > adjList;   // the graph
vector<bool> inStack;   // 1 for nodes that are currently in the stack, 0 otherwise

void tarjanDFS(int i, int par) {
        lowLink[i] = indx[i] = curIndex++;
        stk.push(i);
        inStack[i] = 1;
        for(int j=0;j<adjList[i].size();j++) {
			if(indx[ adjList[i][j] ]==-1 && adjList[i][j]!=par) {
				tarjanDFS( adjList[i][j] ,i );
				lowLink[i] = min(lowLink[i],lowLink[ adjList[i][j] ]);
                }
			else if(inStack[ adjList[i][j] ] && adjList[i][j]!=par)
				lowLink[i] = min(lowLink[i],indx[ adjList[i][j] ]);
        }
        if(indx[i] == lowLink[i])       {
                vector<int> v;
                while(!stk.empty()) {
                        int ind = stk.top();
                        stk.pop();
                        v.push_back(ind);                       // updating the answer
                        nodeToCom[ind] = comToNode.size();
                        inStack[ind] = 0;
                        if(ind==i) break;
                }
                comToNode.push_back(v);

        }
}

void tarjanSCC(int n) { // call it in main

        indx = vector<int>(n,-1);
        lowLink = vector<int>(n,-1);
        nodeToCom = vector<int>(n,-1);
        comToNode = vector< vector<int> >();
        inStack = vector<bool>(n,0);
        stk = stack<int>();
        curIndex = 0;

        for(int i=0;i<adjList.size();i++)
                if(indx[i]==-1)
                        tarjanDFS(i,-1);
}
vector<pair<ii,int> > edge;
vector<vector<ii> > g;
vi x;
int s,t;
bool dfs(int u,bool b){
    lp(i,0,g[u].size()){
        int v=g[u][i].first;
        int c=g[u][i].second;
        if(u==t)return b;
        dfs(v,b||c);
    }
    return b;
}
int main() {
#ifndef ONLINE_JUDGE
    READ;
#endif
    FastIO;
    int n,m;
    cin>>n>>m;
    adjList.resize(n);
    lp(i,0,m){
        int u,v,w;
        cin>>u>>v>>w;
        u--,v--;
        adjList[u].pb(v);
        adjList[v].pb(u);
        edge.pb(MP(MP(u,v),w));
    }
    cin>>s>>t;
    tarjanSCC(n);
    g.resize(comToNode.size());
    x.resize(comToNode.size(),0);
    lp(i,0,m){
        int a=nodeToCom[edge[i].first.first];
        int b=nodeToCom[edge[i].first.second];
        int c=edge[i].second;
        if(a==b){
            x[a]=(x[a]||c);
            x[b]=(x[b]||c);
        }
        else{
            g[a].pb(MP(b,c));
            x[a]=(x[a]||c);
            x[b]=(x[b]||c);
        }
    }
    s--,t--;
    s=nodeToCom[s],t=nodeToCom[t];
    if(dfs(s,x[s]))cout<<"YES";else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi              vector <int>
#define vvi             vector < vi >
#define ii              pair < int,int >
#define vii             vector < ii >
#define all(v)          ((v).begin()), ((v).end())
#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(ll i=0;i<sz(v);++i)
#define lp(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb              push_back
#define MP              make_pair
#define READ            freopen("in.txt","r",stdin)
#define WRITE           freopen("output.txt","w",stdout)
#define scf(n)          scanf("%d",&n)
#define FastIO          ios_base::sync_with_stdio(false)
#define vb              vector <bool>
#define ull unsigned long long
#define REP0(i,n) for (int i = 0; i<n; i++)
#define REP(i,x,n) for (int i = x; i<n; i++)
#define REV0(i,n) for (int i = n - 1; i>=0; i--)
#define REV(i,x,n) for (int i = n - x - 1; i>=0; i--)

typedef long long ll;

vector< vector<int> > comToNode;
vector<int> nodeToCom;

vector<int> indx;               // order of each node in the DFS, initialized by -1
vector<int> lowLink;    // after runing the algorithm, it has a unique indx for each component, this indx is the minimum indx for the set of nodes in that component
stack<int> stk;                 // has the current nodes currently in the stack
int curIndex;
vector<vector<int> > adjList;   // the graph
vector<bool> inStack;   // 1 for nodes that are currently in the stack, 0 otherwise

void tarjanDFS(int i, int par) {
        lowLink[i] = indx[i] = curIndex++;
        stk.push(i);
        inStack[i] = 1;
        for(int j=0;j<adjList[i].size();j++) {
			if(indx[ adjList[i][j] ]==-1 && adjList[i][j]!=par) {
				tarjanDFS( adjList[i][j] ,i );
				lowLink[i] = min(lowLink[i],lowLink[ adjList[i][j] ]);
                }
			else if(inStack[ adjList[i][j] ] && adjList[i][j]!=par)
				lowLink[i] = min(lowLink[i],indx[ adjList[i][j] ]);
        }
        if(indx[i] == lowLink[i])       {
                vector<int> v;
                while(!stk.empty()) {
                        int ind = stk.top();
                        stk.pop();
                        v.push_back(ind);                       // updating the answer
                        nodeToCom[ind] = comToNode.size();
                        inStack[ind] = 0;
                        if(ind==i) break;
                }
                comToNode.push_back(v);

        }
}

void tarjanSCC(int n) { // call it in main

        indx = vector<int>(n,-1);
        lowLink = vector<int>(n,-1);
        nodeToCom = vector<int>(n,-1);
        comToNode = vector< vector<int> >();
        inStack = vector<bool>(n,0);
        stk = stack<int>();
        curIndex = 0;

        for(int i=0;i<adjList.size();i++)
                if(indx[i]==-1)
                        tarjanDFS(i,-1);
}
vector<pair<ii,int> > edge;
vector<vector<ii> > g;
vi x;
int s,t;
bool dfs(int u,bool b){
    lp(i,0,g[u].size()){
        int v=g[u][i].first;
        int c=g[u][i].second;
        if(u==t)return b;
        dfs(v,b||c);
    }
    return b;
}
int main() {
#ifndef ONLINE_JUDGE
    READ;
#endif
    FastIO;
    int n,m;
    cin>>n>>m;
    adjList.resize(n);
    lp(i,0,m){
        int u,v,w;
        cin>>u>>v>>w;
        u--,v--;
        adjList[u].pb(v);
        adjList[v].pb(u);
        edge.pb(MP(MP(u,v),w));
    }
    cin>>s>>t;
    tarjanSCC(n);
    g.resize(comToNode.size());
    x.resize(comToNode.size(),0);
    lp(i,0,m){
        int a=nodeToCom[edge[i].first.first];
        int b=nodeToCom[edge[i].first.second];
        int c=edge[i].second;
        if(a==b){
            x[a]=(x[a]||c);
            //x[b]=(x[b]||c);
        }
        else{
            g[a].pb(MP(b,c));
            x[a]=(x[a]||c);
            //x[b]=(x[b]||c);
        }
    }
    s--,t--;
    s=nodeToCom[s],t=nodeToCom[t];
    if(dfs(s,x[s]))cout<<"YES";else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 300005;

vector<int> G[MAX_N],graph[MAX_N];
vector<P> bridge,check[MAX_N];
int ord[MAX_N],low[MAX_N],cmp[MAX_N];
bool visit[MAX_N];

void dfs(int v,int p,int &k)
{
	visit[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	rep(i,G[v].size()){
		if(!visit[G[v][i]]){
			dfs(G[v][i],v,k);
			low[v] = min(low[v],low[G[v][i]]);
			if(ord[v] < low[G[v][i]]){
				bridge.pb(P(v,G[v][i]));
                check[v][i].se = 1;
                check[G[v][i]][check[v][i].fi].se = 1;
			}
		}else if(G[v][i] != p){
			low[v] = min(low[v],ord[G[v][i]]);
		}
	}
}

void add_edge(int u,int v)
{
    G[u].pb(v),G[v].pb(u);
    check[u].pb(P((int)check[v].size(),0));
    check[v].pb(P((int)check[u].size()-1,0));
}

void restrict_dfs(int u,int p,int kind,queue<int>& que)
{
    visit[u] = true;
    cmp[u] = kind;
    rep(i,G[u].size()){
        if(check[u][i].se){
            if(!visit[G[u][i]]){
                que.push(G[u][i]);
            }
        }else if(!visit[G[u][i]]){
            restrict_dfs(G[u][i],u,kind,que);
        }
    }
}

int make_graph(int V)
{
    int num = 0;
    fill(visit,visit+V,false);
    rep(i,V){
        if(!visit[i]){
            dfs(i,-1,num);
        }
    }
    fill(visit,visit+V,false);
    int kind = 0;
    rep(i,V){
        if(!visit[i]){
            queue<int> que;
            que.push(i);
            while(!que.empty()){
                int p = que.front();
                que.pop();
                restrict_dfs(p,-1,kind,que);
                kind++;
            }
        }
    }
    rep(i,bridge.size()){
        int a = cmp[bridge[i].fi];
        int b = cmp[bridge[i].se];
        graph[a].pb(b);
        graph[b].pb(a);
    }
    return kind;
}

bool ans,ed;
int s,g;
vector<int> kd[MAX_N];
set<P> hasi;
set<int> node;

void dfs_find(int u,int p,vector<int>& route)
{
    if(u == cmp[g]){
		rep(i,route.size()){
			if(node.count(cmp[route[i]]) > 0){
				ans = true;
				break;
			}
			if(i < (int)route.size() - 1){
				if(hasi.count(P(cmp[route[i]],cmp[route[i+1]])) > 0){
					ans = true;
					break;
				}
			}
		}
        ed = true;
        return;
    }
    rep(i,graph[u].size()){
        if(graph[u][i] != p){
			route.pb(graph[u][i]);
            dfs_find(graph[u][i],u,route);
			route.pop_back();
            if(ed){
                return;
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        add_edge(a-1,b-1);
        kd[a-1].pb(c),kd[b-1].pb(c);
    }
    cin >> s >> g;
    s--,g--;
    int cnt = make_graph(n);
    rep(i,n){
        rep(j,G[i].size()){
            if(cmp[i] != cmp[G[i][j]]){
                if(kd[i][j] == 1){
                    hasi.insert(P(cmp[i],cmp[G[i][j]]));
                    hasi.insert(P(cmp[G[i][j]],cmp[i]));
                }
            }else{
				if(kd[i][j] == 1){
					node.insert(cmp[i]);
				}
            }
        }
    }
    ans = ed = false;
	vector<int> v;
	v.pb(cmp[s]);
    dfs_find(cmp[s],-1,v);
    if(ans){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 300005;

vector<int> G[MAX_N],graph[MAX_N];
vector<P> bridge,check[MAX_N];
int ord[MAX_N],low[MAX_N],cmp[MAX_N];
bool visit[MAX_N];

void dfs(int v,int p,int &k)
{
	visit[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	rep(i,G[v].size()){
		if(!visit[G[v][i]]){
			dfs(G[v][i],v,k);
			low[v] = min(low[v],low[G[v][i]]);
			if(ord[v] < low[G[v][i]]){
				bridge.pb(P(v,G[v][i]));
                check[v][i].se = 1;
                check[G[v][i]][check[v][i].fi].se = 1;
			}
		}else if(G[v][i] != p){
			low[v] = min(low[v],ord[G[v][i]]);
		}
	}
}

void add_edge(int u,int v)
{
    G[u].pb(v),G[v].pb(u);
    check[u].pb(P((int)check[v].size(),0));
    check[v].pb(P((int)check[u].size()-1,0));
}

void restrict_dfs(int u,int p,int kind,queue<int>& que)
{
    visit[u] = true;
    cmp[u] = kind;
    rep(i,G[u].size()){
        if(check[u][i].se){
            if(!visit[G[u][i]]){
                que.push(G[u][i]);
            }
        }else if(!visit[G[u][i]]){
            restrict_dfs(G[u][i],u,kind,que);
        }
    }
}

int make_graph(int V)
{
    int num = 0;
    fill(visit,visit+V,false);
    rep(i,V){
        if(!visit[i]){
            dfs(i,-1,num);
        }
    }
    fill(visit,visit+V,false);
    int kind = 0;
    rep(i,V){
        if(!visit[i]){
            queue<int> que;
            que.push(i);
            while(!que.empty()){
                int p = que.front();
                que.pop();
                restrict_dfs(p,-1,kind,que);
                kind++;
            }
        }
    }
    rep(i,bridge.size()){
        int a = cmp[bridge[i].fi];
        int b = cmp[bridge[i].se];
        graph[a].pb(b);
        graph[b].pb(a);
    }
    return kind;
}

bool ans,ed;
int s,g;
vector<int> kd[MAX_N];
set<P> hasi;
set<int> node;

void dfs_find(int u,int p)
{
    if(node.count(u) > 0){
        ans = true;
    }
    if(u == cmp[g]){
        ed = true;
        return;
    }
    rep(i,graph[u].size()){
        if(graph[u][i] != p){
            if(hasi.count(P(u,graph[u][i])) > 0){
                ans = true;
            }
            dfs_find(graph[u][i],u);
            if(ed){
                return;
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        add_edge(a-1,b-1);
        kd[a-1].pb(c),kd[b-1].pb(c);
    }
    cin >> s >> g;
    s--,g--;
    int cnt = make_graph(n);
    rep(i,n){
        rep(j,G[i].size()){
            if(cmp[i] != cmp[G[i][j]]){
                if(kd[i][j] == 1){
                    hasi.insert(P(cmp[i],cmp[G[i][j]]));
                    hasi.insert(P(cmp[G[i][j]],cmp[i]));
                }
            }else{
                node.insert(cmp[i]);
            }
        }
    }
    ans = ed = false;
    dfs_find(cmp[s],-1);
    if(ans){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 300005;

vector<int> G[MAX_N],graph[MAX_N];
vector<P> bridge,check[MAX_N];
int ord[MAX_N],low[MAX_N],cmp[MAX_N];
bool visit[MAX_N];

void dfs(int v,int p,int &k)
{
	visit[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	rep(i,G[v].size()){
		if(!visit[G[v][i]]){
			dfs(G[v][i],v,k);
			low[v] = min(low[v],low[G[v][i]]);
			if(ord[v] < low[G[v][i]]){
				bridge.pb(P(v,G[v][i]));
                check[v][i].se = 1;
                check[G[v][i]][check[v][i].fi].se = 1;
			}
		}else if(G[v][i] != p){
			low[v] = min(low[v],ord[G[v][i]]);
		}
	}
}

void add_edge(int u,int v)
{
    G[u].pb(v),G[v].pb(u);
    check[u].pb(P((int)check[v].size(),0));
    check[v].pb(P((int)check[u].size()-1,0));
}

void restrict_dfs(int u,int p,int kind,queue<int>& que)
{
    visit[u] = true;
    cmp[u] = kind;
    rep(i,G[u].size()){
        if(check[u][i].se){
            if(!visit[G[u][i]]){
                que.push(G[u][i]);
            }
        }else if(!visit[G[u][i]]){
            restrict_dfs(G[u][i],u,kind,que);
        }
    }
}

int make_graph(int V)
{
    int num = 0;
    fill(visit,visit+V,false);
    rep(i,V){
        if(!visit[i]){
            dfs(i,-1,num);
        }
    }
    fill(visit,visit+V,false);
    int kind = 0;
    rep(i,V){
        if(!visit[i]){
            queue<int> que;
            que.push(i);
            while(!que.empty()){
                int p = que.front();
                que.pop();
                restrict_dfs(p,-1,kind,que);
                kind++;
            }
        }
    }
    rep(i,bridge.size()){
        int a = cmp[bridge[i].fi];
        int b = cmp[bridge[i].se];
        graph[a].pb(b);
        graph[b].pb(a);
    }
    return kind;
}

bool ans,ed;
int s,g;
vector<int> kd[MAX_N];
set<P> hasi;
set<int> node;

void dfs_find(int u,int p,vector<int>& route)
{
    if(u == cmp[g]){
		rep(i,route.size()){
			if(node.count(route[i]) > 0){
				ans = true;
				break;
			}
			if(i < (int)route.size() - 1){
				if(hasi.count(P(route[i],route[i+1])) > 0){
					ans = true;
					break;
				}
			}
		}
        ed = true;
        return;
    }
    rep(i,graph[u].size()){
        if(graph[u][i] != p){
			route.pb(graph[u][i]);
            dfs_find(graph[u][i],u,route);
			route.pop_back();
            if(ed){
                return;
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        add_edge(a-1,b-1);
        kd[a-1].pb(c),kd[b-1].pb(c);
    }
    cin >> s >> g;
    s--,g--;
    int cnt = make_graph(n);
    rep(i,n){
        rep(j,G[i].size()){
            if(cmp[i] != cmp[G[i][j]]){
                if(kd[i][j] == 1){
                    hasi.insert(P(cmp[i],cmp[G[i][j]]));
                    hasi.insert(P(cmp[G[i][j]],cmp[i]));
                }
            }else{
				if(kd[i][j] == 1){
					node.insert(cmp[i]);
				}
            }
        }
    }
    ans = ed = false;
	vector<int> v;
	v.pb(cmp[s]);
    dfs_find(cmp[s],-1,v);
    if(ans){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}