int main() {
unsigned long long int t,n,m;
cin>>t;
bool check;
while(t–)
{ check=false;
cin>>n>>m;
if(n%2==0 && m%2==0)
check=true;
else if(n%2==0 || m%2==0)
check=true;
if(n==1 || m==1)
{ long long int sum=(abs)(n-m);
Please have a look on my code and please clear where I did not satisfy the HAMILTONIAN CYCLE’S CONDITION ??.. It would be great if anyone answers it ! .Sorry for the long code , Iam a beginner!
Thanks in advance! #include
using namespace std;
int main() {
int t,n,m;
cin>>t;
for(int i=0;i<t;i++)
{
A path is defined as magical if it starts from any of the cell (a,b) of the maze and ends at the cell (c,d) such that the following conditions are satisfied :-
|a - c| + |b - d| = 1
All the cells in the maze are traversed exactly once.
It is allowed to move only in the four directions - up, down, left and right from the current cell.
THIS IS THE CONDITION for magical path
so lets take an eg n=5 , m=5 matrix , can’t we traverse from (1,1) to (5,1) |a - c| + |b - d| = 1 it holds this condition;
then move to (5,2) then move to upward till (1,2) |a - c| + |b - d| = 1 it holds this condition; then again, (1,3) to (5,3)… and so on till we reach (5,5) ;
we literally satisfied all the conditon i.e sum should be =1 , we should traverse all the cell ; and we can either go up, down, left or right from the current cell; so, why there is no magical path???
Can anyone tell me why should ending cell (c, d) be adjacent to starting cell? I am not getting this as it is not mentioned anywhere in problem statement but I don’t know why they have put this statement in editorial.