#include <iostream>
#include <cassert>
using namespace std;
const int N = 5;
const int M = 5;
char Matrix[N][M];
typedef pair<int,int> point;
#define x first
#define y second
bool valid(point test){
return test.x>=0 && test.x < N && test.y >= 0 && test.y < M && Matrix[test.x][test.y];
}
point add(point cur,int dir){
switch (dir){
case 0: return point(cur.x + 1, cur.y);
case 1: return point(cur.x - 1, cur.y);
case 2: return point(cur.x, cur.y + 1);
case 3: return point(cur.x, cur.y - 1);
default: assert(false); //wrong dir
}
}
char Used[N][M];
bool dfs(point cur, point goal, int countStep){
countStep++;
Used[cur.x][cur.y] = 1;
for (int i=0;i<4;i++){
point nnew = add(cur,i);
if (!valid(nnew))
continue;
if (nnew == goal && countStep>2){
cout << "path find, step = " << countStep<<endl;
cout << cur.x<<" "<<cur.y<<endl;
return true;
}
if (Used[nnew.x][nnew.y])
continue;
if (dfs(nnew,goal,countStep)){
cout << cur.x<<" "<<cur.y<<endl;
return true;
}
}
return false;
}
int main() {
// Init
Matrix[2][3] = 1;
Matrix[2][2] = 1;
Matrix[1][1] = 1;
Matrix[1][2] = 1;
Matrix[2][1] = 1;
//
point cur = point(2,3);
assert(valid(cur));
if (!dfs(cur, cur,0))
cout <<"No path"<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2Fzc2VydD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBOID0gNTsKY29uc3QgaW50IE0gPSA1OwpjaGFyIE1hdHJpeFtOXVtNXTsKCnR5cGVkZWYgcGFpcjxpbnQsaW50PiBwb2ludDsKI2RlZmluZSB4IGZpcnN0CiNkZWZpbmUgeSBzZWNvbmQKCmJvb2wgdmFsaWQocG9pbnQgdGVzdCl7CiAgICByZXR1cm4gdGVzdC54Pj0wICYmIHRlc3QueCA8IE4gJiYgdGVzdC55ID49IDAgJiYgdGVzdC55IDwgTSAmJiBNYXRyaXhbdGVzdC54XVt0ZXN0LnldOwp9Cgpwb2ludCBhZGQocG9pbn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