#include <iostream>
#include <vector>
#include <queue>
#define ARR 16
using namespace std;
int asw;
int map[ARR][ARR] = { 0, };
int chk[ARR][ARR] = { 0, };
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,-1,0,1 };
void bfs(int starty, int startx)
{
chk[starty][startx] = 1;
queue<pair<int, int>> qCon;
qCon.push(make_pair(starty, startx));
while (!qCon.empty())
{
int y = qCon.front().first;
int x = qCon.front().second;
qCon.pop();//꺼냈으므로 pop해야댐
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if (nx >= 0 && ny >= 0 && nx < ARR && ny < ARR) //기본조건 배열 바운드리 안에 있어야한다.
{
if (map[ny][nx] == 3)
{
asw = 1; //이때 1반환.
return;
}
if ((chk[ny][nx] != 1) && (map[ny][nx] == 0) )//3일땐 최종이고, 0일땐 다음경로이다.
{
chk[ny][nx] = 1;
qCon.push(make_pair(ny,nx));
}
}
}
}
}
int main() {
for (int test_case = 0; test_case < 10; test_case++)
{
int iTemp; cin >> iTemp;
int iResult;
for (int i = 0; i < ARR; i++)
{
for (int j = 0; j < ARR; j++)
{
scanf("%1d", &map[i][j]);
}
}
asw = 0;
for (int i = 0; i < ARR; i++)
{
for (int j = 0; j < ARR; j++)
{
if (map[i][j] == 2)
{
bfs(i, j);
}
}
}
printf("#%d %d", test_case + 1, asw);
for (int i = 0; i < ARR; i++)
{
for (int j = 0; j < ARR; j++)
{
chk[i][j] = 0;
}
}
cout << endl;
}
return 0 ;
}
뒤에 chk = 0안해버리는 바람에
테스트케이스 개별로 넣어도 도대체 어디가 잘못되서 이런건지 한참을 찾았다.