#include <iostream>
#include <algorithm>
#include <vector>
#pragma region 빠른 입출력
#define FAST_IO() \
{\
ios::sync_with_stdio(false);\
cin.tie(NULL); \
cout.tie(NULL); \
}\
#pragma endregion
using namespace std;
int graph[1000001];
int GetParent(int x)
{
if (graph[x] == x)
return x;
else
return graph[x] = GetParent(graph[x]);
}
void Union(int a, int b)
{
a = GetParent(a), b = GetParent(b);
graph[a] = b;
}
void Find(int a, int b)
{
if (GetParent(a) == GetParent(b))
cout << "YES\n";
else
cout << "NO\n";
}
int main()
{
FAST_IO();
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
graph[i] = i;
for (int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
if (a == 0)
Union(b, c);
else
Find(b, c);
}
return 0;
}