#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
using namespace std;
int num_wall;
int x0_m,y0_m;
int x0_r,y0_r;
int x_exist,y_exist;
int x1,y1;
int x2,y2;
int bug;
int position[30][3];
int caught();
char maze[6][6];
bool flag[6][6];
void input();
void init();
void search();
void mov_m();
queue<int> row_r;
queue<int> col_r;
queue<int> row_m;
queue<int> col_m;
int main()
{
input();
init();
while(bug==0&&!row_r.empty())
{
search();
}
if(bug==0)
{
printf("No\n");
}
return 0;
}
void input()
{
int i,j;
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
maze[i][j]='O';
}
}
scanf("%d\n",&num_wall);
for(i=0;i<num_wall;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&position[i][j]);
}
}
for(i=0;i<num_wall;i++)
{
if(position[i][2]==0)
{
maze[position[i][0]+1][position[i][1]]='X';
}
if(position[i][2]==1)
{
maze[position[i][0]][position[i][1]+1]='X';
}
}
scanf("%d %d\n",&x0_m,&y0_m);
scanf("%d %d\n",&x0_r,&y0_r);
scanf("%d %d",&x_exist,&y_exist);
}
void init()
{
row_r.push(x0_r);
col_r.push(y0_r);
row_m.push(x0_m);
col_m.push(y0_m);
flag[x0_r][y0_r]=1;
}
void search()
{
int p,q,r,s;
p=row_r.front();
row_r.pop();
q=col_r.front();
col_r.pop();
r=row_m.front();
row_m.pop();
s=col_m.front();
col_m.pop();
x1=p;
y1=q;
x2=r;
y2=s;
if(x1>0&&maze[x1-1][y1]=='O')
{
x1=x1-1;
y1=y1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
x1=p;
y1=q;
x2=r;
y2=s;
if(x1<5&&maze[x1+1][y1]=='O')
{
x1=x1+1;
y1=y1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
x1=p;
y1=q;
x2=r;
y2=s;
if(y1>0&&maze[x1][y1-1]=='O')
{
x1=x1;
y1=y1-1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
x1=p;
y1=q;
x2=r;
y2=s;
if(y1<5&&maze[x1][y1+1]=='O')
{
x1=x1;
y1=y1+1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
}
int caught()
{
if(x1!=x2||y1!=y2)
{
return 1;
}
else
{
return 0;
}
}
void mov_m()
{
if(y2<y1&&maze[x2][y2+1]=='O')
{
y2=y2+1;
x2=x2;
if(caught()==1)
{
if(y2<y1&&maze[x2][y2+1]=='O')
{
y2=y2+1;
x2=x2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(y2<y1&&maze[x2][y2+1]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(y2==y1)
{
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
}
}
else if(y2<y1&&maze[x2][y2+1]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(y2==y1)
{
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='O')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(y2>y1&&maze[x2][y2-1]=='O')
{
y2=y2-1;
x2=x2;
if(caught()==1)
{
if(y2>y1&&maze[x2][y2-1]=='O')
{
y2=y2-1;
x2=x2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(y2>y1&&maze[x2][y2-1]=='O')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(y2==y1)
{
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
}
}
else if(y2>y1&&maze[x2][y2-1]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
#include<string.h>
#include<stdlib.h>
#include<queue>
using namespace std;
int num_wall;
int x0_m,y0_m;
int x0_r,y0_r;
int x_exist,y_exist;
int x1,y1;
int x2,y2;
int bug;
int position[30][3];
int caught();
char maze[6][6];
bool flag[6][6];
void input();
void init();
void search();
void mov_m();
queue<int> row_r;
queue<int> col_r;
queue<int> row_m;
queue<int> col_m;
int main()
{
input();
init();
while(bug==0&&!row_r.empty())
{
search();
}
if(bug==0)
{
printf("No\n");
}
return 0;
}
void input()
{
int i,j;
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
maze[i][j]='O';
}
}
scanf("%d\n",&num_wall);
for(i=0;i<num_wall;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&position[i][j]);
}
}
for(i=0;i<num_wall;i++)
{
if(position[i][2]==0)
{
maze[position[i][0]+1][position[i][1]]='X';
}
if(position[i][2]==1)
{
maze[position[i][0]][position[i][1]+1]='X';
}
}
scanf("%d %d\n",&x0_m,&y0_m);
scanf("%d %d\n",&x0_r,&y0_r);
scanf("%d %d",&x_exist,&y_exist);
}
void init()
{
row_r.push(x0_r);
col_r.push(y0_r);
row_m.push(x0_m);
col_m.push(y0_m);
flag[x0_r][y0_r]=1;
}
void search()
{
int p,q,r,s;
p=row_r.front();
row_r.pop();
q=col_r.front();
col_r.pop();
r=row_m.front();
row_m.pop();
s=col_m.front();
col_m.pop();
x1=p;
y1=q;
x2=r;
y2=s;
if(x1>0&&maze[x1-1][y1]=='O')
{
x1=x1-1;
y1=y1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
x1=p;
y1=q;
x2=r;
y2=s;
if(x1<5&&maze[x1+1][y1]=='O')
{
x1=x1+1;
y1=y1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
x1=p;
y1=q;
x2=r;
y2=s;
if(y1>0&&maze[x1][y1-1]=='O')
{
x1=x1;
y1=y1-1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
x1=p;
y1=q;
x2=r;
y2=s;
if(y1<5&&maze[x1][y1+1]=='O')
{
x1=x1;
y1=y1+1;
if(caught()==1)
{
if(x1==x_exist&&y1==y_exist)
{
printf("Yes\n");
bug=1;
return ;
}
else
{
mov_m();
}
}
}
}
int caught()
{
if(x1!=x2||y1!=y2)
{
return 1;
}
else
{
return 0;
}
}
void mov_m()
{
if(y2<y1&&maze[x2][y2+1]=='O')
{
y2=y2+1;
x2=x2;
if(caught()==1)
{
if(y2<y1&&maze[x2][y2+1]=='O')
{
y2=y2+1;
x2=x2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(y2<y1&&maze[x2][y2+1]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(y2==y1)
{
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
}
}
else if(y2<y1&&maze[x2][y2+1]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(y2==y1)
{
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='O')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(y2>y1&&maze[x2][y2-1]=='O')
{
y2=y2-1;
x2=x2;
if(caught()==1)
{
if(y2>y1&&maze[x2][y2-1]=='O')
{
y2=y2-1;
x2=x2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(y2>y1&&maze[x2][y2-1]=='O')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(y2==y1)
{
if(x2<x1&&maze[x2+1][y2]=='O')
{
x2=x2+1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2<x1&&maze[x2+1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
else if(x2>x1&&maze[x2-1][y2]=='O')
{
x2=x2-1;
y2=y2;
if(caught()==1&&flag[x1][y1]==0)
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
else if(x2>x1&&maze[x2-1][y2]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}
}
}
else if(y2>y1&&maze[x2][y2-1]=='X')
{
row_r.push(x1);
col_r.push(y1);
row_m.push(x2);
col_m.push(y2);
flag[x1][y1]=1;
}
}