#include <bits/stdc++.h>
using
namespace
std;
void
printExistPath(stack<
int
> sx, stack<
int
> sy,
int
last)
{
if
(sx.empty() || sy.empty()) {
return
;
}
int
x = sx.top();
int
y = sy.top();
sx.pop();
sy.pop();
printExistPath(sx, sy, last);
if
(sx.size() == last - 1) {
cout <<
"("
<< x <<
", "
<< y <<
")"
;
}
else
{
cout <<
"("
<< x <<
", "
<< y <<
") -> "
;
}
}
bool
storePath(
int
srcX,
int
srcY,
int
destX,
int
destY,
stack<
int
>& sx, stack<
int
>& sy)
{
if
(srcX > destX || srcY > destY) {
return
false
;
}
sx.push(srcX);
sy.push(srcY);
if
(srcX == destX && srcY == destY) {
printExistPath(sx, sy, sx.size());
return
true
;
}
if
(storePath((2 * srcX) + srcY, srcY, destX, destY, sx, sy)) {
return
true
;
}
if
(storePath(srcX, (2 * srcY) + srcX, destX, destY, sx, sy)) {
return
true
;
}
sx.pop();
sy.pop();
return
false
;
}
bool
isPathExist(
int
srcX,
int
srcY,
int
destX,
int
destY)
{
stack<
int
> sx;
stack<
int
> sy;
return
storePath(srcX, srcY, destX, destY, sx, sy);
}
void
printPath(
int
srcX,
int
srcY,
int
destX,
int
destY)
{
if
(!isPathExist(srcX, srcY, destX, destY))
{
cout <<
"-1"
;
}
}
int
main()
{
int
srcX = 5, srcY = 8;
int
destX = 83, destY = 21;
printPath(srcX, srcY, destX, destY);
}