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("3 3");
WillReturn.Add("10");
WillReturn.Add("1 2 2");
WillReturn.Add("1 1 1");
WillReturn.Add("2 1 1 2 2");
WillReturn.Add("1 3 2");
WillReturn.Add("2 1 1 2 2");
WillReturn.Add("2 2 2 3 2");
WillReturn.Add("1 2 3");
WillReturn.Add("1 2 1");
WillReturn.Add("2 1 1 2 2");
WillReturn.Add("2 1 1 3 3");
//No
//No
//Yes
//Yes
//No
}
else if (InputPattern == "Input2") {
WillReturn.Add("1 1");
WillReturn.Add("3");
WillReturn.Add("2 1 1 1 1");
WillReturn.Add("1 1 1");
WillReturn.Add("2 1 1 1 1");
//No
//Yes
}
else if (InputPattern == "Input3") {
WillReturn.Add("5 5");
WillReturn.Add("42");
WillReturn.Add("2 3 4 3 4");
WillReturn.Add("2 3 2 3 2");
WillReturn.Add("1 4 1");
WillReturn.Add("2 4 1 2 2");
WillReturn.Add("1 1 2");
WillReturn.Add("1 4 5");
WillReturn.Add("1 3 3");
WillReturn.Add("2 4 2 1 3");
WillReturn.Add("1 3 5");
WillReturn.Add("2 2 4 2 3");
WillReturn.Add("2 2 4 2 5");
WillReturn.Add("2 3 4 5 1");
WillReturn.Add("2 3 1 2 2");
WillReturn.Add("2 3 1 1 2");
WillReturn.Add("2 2 4 5 2");
WillReturn.Add("2 3 2 5 3");
WillReturn.Add("1 4 3");
WillReturn.Add("2 3 3 3 5");
WillReturn.Add("2 3 1 3 2");
WillReturn.Add("1 1 5");
WillReturn.Add("2 4 4 5 3");
WillReturn.Add("1 1 4");
WillReturn.Add("2 1 3 2 5");
WillReturn.Add("2 4 3 1 4");
WillReturn.Add("2 2 3 3 3");
WillReturn.Add("1 2 1");
WillReturn.Add("1 2 5");
WillReturn.Add("2 1 4 5 3");
WillReturn.Add("2 4 4 2 5");
WillReturn.Add("2 4 2 2 4");
WillReturn.Add("1 2 2");
WillReturn.Add("2 4 1 5 2");
WillReturn.Add("1 2 4");
WillReturn.Add("2 3 1 4 1");
WillReturn.Add("1 4 4");
WillReturn.Add("2 3 2 2 1");
WillReturn.Add("2 1 1 5 2");
WillReturn.Add("1 4 2");
WillReturn.Add("2 4 2 3 5");
WillReturn.Add("1 3 2");
WillReturn.Add("1 3 4");
WillReturn.Add("1 2 3");
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//No
//Yes
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => int.Parse(pX)).ToArray();
SplitAct(InputList[0]);
int H = wkArr[0];
int W = wkArr[1];
var RedSet = new HashSet<int>();
var InsUnionFind = new UnionFind();
foreach (string EachStr in InputList.Skip(2)) {
SplitAct(EachStr);
if (wkArr[0] == 1) {
int X = wkArr[2];
int Y = wkArr[1];
int Hash = GetHash(X, Y);
if (RedSet.Add(Hash)) {
InsUnionFind.MakeSet(Hash);
// 4近傍とUniteする
Action<int, int> UniteAct = (pTargetX, pTargetY) =>
{
if (pTargetX < 1 || W < pTargetX) return;
if (pTargetY < 1 || H < pTargetY) return;
int TargetHash = GetHash(pTargetX, pTargetY);
if (RedSet.Contains(TargetHash) == false) {
return;
}
InsUnionFind.Unite(Hash, TargetHash);
};
UniteAct(X, Y - 1);
UniteAct(X, Y + 1);
UniteAct(X - 1, Y);
UniteAct(X + 1, Y);
}
}
if (wkArr[0] == 2) {
int X1 = wkArr[2];
int Y1 = wkArr[1];
int X2 = wkArr[4];
int Y2 = wkArr[3];
int Hash1 = GetHash(X1, Y1);
int Hash2 = GetHash(X2, Y2);
bool IsYes = false;
if (RedSet.Contains(Hash1) && RedSet.Contains(Hash2)) {
int Root1 = InsUnionFind.FindSet(Hash1);
int Root2 = InsUnionFind.FindSet(Hash2);
if (Root1 == Root2) {
IsYes = true;
}
}
Console.WriteLine(IsYes ? "Yes" : "No");
}
}
}
// ハッシュ値を返す
static int GetHash(int pX, int pY)
{
return pX * 10000 + pY;
}
}
#region UnionFind
// UnionFindクラス
internal class UnionFind
{
private class NodeInfoDef
{
internal int ParentNode;
internal int Rank;
}
private Dictionary<int, NodeInfoDef> mNodeInfoDict =
new Dictionary<int, NodeInfoDef>();
// 要素が1つである木を森に追加
internal void MakeSet(int pNode)
{
NodeInfoDef WillAdd = new NodeInfoDef();
WillAdd.ParentNode = pNode;
WillAdd.Rank = 0;
mNodeInfoDict[pNode] = WillAdd;
}
// 合併処理
internal void Unite(int pX, int pY)
{
int XNode = FindSet(pX);
int YNode = FindSet(pY);
int XRank = mNodeInfoDict[XNode].Rank;
int YRank = mNodeInfoDict[YNode].Rank;
if (XRank > YRank) {
mNodeInfoDict[YNode].ParentNode = XNode;
}
else {
mNodeInfoDict[XNode].ParentNode = YNode;
if (XRank == YRank) {
mNodeInfoDict[YNode].Rank++;
}
}
}
// ノードを引数として、木の根を取得
internal int FindSet(int pTargetNode)
{
// 根までの経路上のノードのList
var PathNodeList = new List<int>();
int CurrNode = pTargetNode;
while (CurrNode != mNodeInfoDict[CurrNode].ParentNode) {
PathNodeList.Add(CurrNode);
CurrNode = mNodeInfoDict[CurrNode].ParentNode;
}
// 経路圧縮 (親ポインタの付け替え)
foreach (int 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