using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5 3");
WillReturn.Add("1 3");
WillReturn.Add("2 3");
WillReturn.Add("4 5");
WillReturn.Add("4");
WillReturn.Add("1 1 4");
WillReturn.Add("3 1 5");
WillReturn.Add("2 2 3");
WillReturn.Add("3 1 5");
//Yes
//Yes
}
else if (InputPattern == "Input2") {
WillReturn.Add("5 2");
WillReturn.Add("1 3");
WillReturn.Add("2 4");
WillReturn.Add("2");
WillReturn.Add("2 2 4");
WillReturn.Add("2 1 3");
//
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static long mN;
static long mM;
static HashSet<long> mEdgeHashSet = new HashSet<long>();
class QueryInfoDef
{
internal long Type;
internal long FromNode;
internal long ToNode;
internal string Answer;
}
static List<QueryInfoDef> mQueryInfoList = new List<QueryInfoDef>();
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
SplitAct(InputList[0]);
mN = wkArr[0];
mM = wkArr[1];
foreach (string EachStr in InputList.Skip(1).Take((int)mM)) {
SplitAct(EachStr);
long FromNode = wkArr[0];
long ToNode = wkArr[1];
long Hash = GetEdgeHash(FromNode, ToNode);
mEdgeHashSet.Add(Hash);
}
foreach (string EachStr in InputList.Skip(1 + (int)mM + 1)) {
SplitAct(EachStr);
var WillAdd = new QueryInfoDef();
WillAdd.Type = wkArr[0];
WillAdd.FromNode = wkArr[1];
WillAdd.ToNode = wkArr[2];
mQueryInfoList.Add(WillAdd);
}
foreach (QueryInfoDef EachQueryInfo in mQueryInfoList) {
long FromNode = EachQueryInfo.FromNode;
long ToNode = EachQueryInfo.ToNode;
long Hash = GetEdgeHash(FromNode, ToNode);
if (EachQueryInfo.Type == 1) {
mEdgeHashSet.Add(Hash);
}
if (EachQueryInfo.Type == 2) {
mEdgeHashSet.Remove(Hash);
}
}
UnionFind InsUnionFind = InitUnionFind();
int UB = mQueryInfoList.Count - 1;
for (int I = UB; 0 <= I; I--) {
long Type = mQueryInfoList[I].Type;
long FromNode = mQueryInfoList[I].FromNode;
long ToNode = mQueryInfoList[I].ToNode;
long Hash = GetEdgeHash(FromNode, ToNode);
// 辺の追加のキャンセル
if (Type == 1) {
mEdgeHashSet.Remove(Hash);
InsUnionFind = InitUnionFind();
}
// 辺の削除のキャンセル
if (Type == 2) {
mEdgeHashSet.Add(Hash);
InsUnionFind.Unite(FromNode, ToNode);
}
if (Type == 3) {
long Root1 = InsUnionFind.FindSet(FromNode);
long Root2 = InsUnionFind.FindSet(ToNode);
if (Root1 == Root2) {
mQueryInfoList[I].Answer = "Yes";
}
else {
mQueryInfoList[I].Answer = "No";
}
}
}
foreach (QueryInfoDef EachQueryInfo in mQueryInfoList) {
if (EachQueryInfo.Type == 3) {
Console.WriteLine(EachQueryInfo.Answer);
}
}
}
// UnionFindクラスを初期構築して返す
static UnionFind InitUnionFind()
{
var InsUnionFind = new UnionFind();
for (long I = 1; I <= mN; I++) {
InsUnionFind.MakeSet(I);
}
foreach (long EachHash in mEdgeHashSet) {
long FromNode = EachHash / Geta;
long ToNode = EachHash % Geta;
InsUnionFind.Unite(FromNode, ToNode);
}
return InsUnionFind;
}
const long Geta = 1000000;
static long GetEdgeHash(long pFromNode, long pToNode)
{
long MinNode = Math.Min(pFromNode, pToNode);
long MaxNode = Math.Max(pFromNode, pToNode);
return MinNode * Geta + MaxNode;
}
}
#region UnionFind
// UnionFindクラス
internal class UnionFind
{
private class NodeInfoDef
{
internal long ParentNode;
internal long Rank;
}
private Dictionary<long, NodeInfoDef> mNodeInfoDict =
new Dictionary<long, NodeInfoDef>();
// 要素が1つである木を森に追加
internal void MakeSet(long pNode)
{
NodeInfoDef WillAdd = new NodeInfoDef();
WillAdd.ParentNode = pNode;
WillAdd.Rank = 0;
mNodeInfoDict[pNode] = WillAdd;
}
// 合併処理
internal void Unite(long pX, long pY)
{
long XNode = FindSet(pX);
long YNode = FindSet(pY);
long XRank = mNodeInfoDict[XNode].Rank;
long YRank = mNodeInfoDict[YNode].Rank;
if (XRank > YRank) {
mNodeInfoDict[YNode].ParentNode = XNode;
}
else {
mNodeInfoDict[XNode].ParentNode = YNode;
if (XRank == YRank) {
mNodeInfoDict[YNode].Rank++;
}
}
}
// ノードを引数として、木の根を取得
internal long FindSet(long pTargetNode)
{
// 根までの経路上のノードのList
var PathNodeList = new List<long>();
long CurrNode = pTargetNode;
while (CurrNode != mNodeInfoDict[CurrNode].ParentNode) {
PathNodeList.Add(CurrNode);
CurrNode = mNodeInfoDict[CurrNode].ParentNode;
}
// 経路圧縮 (親ポインタの付け替え)
foreach (long EachPathNode in PathNodeList) {
mNodeInfoDict[EachPathNode].ParentNode = CurrNode;
}
return CurrNode;
}
internal void DebugPrint()
{
foreach (var EachPair in mNodeInfoDict.OrderBy(pX => pX.Key)) {
Console.WriteLine("mNodeInfoDict[{0}].ParentNode={1}",
EachPair.Key, EachPair.Value.ParentNode);
}
}
}
#endregion