CHEFPATH - editorial

Can someone tell me whats wrong with this code?

#include
#include
#include
using namespace std;

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);

		if(sum>1)
			check=false;
	}
	if(check)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}
return 0;

}

@rohitkoush “Yes” should be printed instead of “YES”, same is the case for “No”.

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++)
{

cin>>n>>m;
if(n==1 || m==1)
{
if(n==1 && m==1)
{
cout<<“No”<<"\n";
}

                    if(n==1 && m==2)
                    {
                            cout<<"Yes"<<"\n";
                    }
                    
                    
                    if(n==1 && m>2)
                    {
                            cout<<"No"<<"\n";
                    }
                    
                    if(m==1 && n==2)
                    {
                            cout<<"Yes"<<"\n";
                    }
                    
                    if(m==1 && n>2)
                    {
                            cout<<"No";
                    }
            }
            
            
            if(n==2 || m==2)
            
            { 
            	if(m==2 && n==2)
            {
                    cout<<"Yes"<<"\n";
            }
            
            if(n==2 && m>2 )
            {cout<<"Yes"<<"\n";
            }
            
                    if(m==2 && n>2)
                    {cout<<"Yes"<<"\n";
                            
                    }
            
            }
                                   
    if(n>2 && m>2)
    {
            if(n%2!=0 && m%2!=0)
            {
                    cout<<"No"<<"\n";
            }
            
            if(n%2==0 && m%2==0)
            {
                    cout<<"Yes"<<"\n";
            }
            
            if(n%2!=0 && m%2==0)
            {
                    cout<<"Yes"<<"\n";
            }
            
            if(n%2==0 && m%2!=0)
        {
            cout<<"Yes"<<"\n";
        }
    
    }
    }

}

hi, can someone help point out the issue with the below code?

InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);

    int tc = Integer.valueOf(br.readLine().trim());
    for(int i=0;i<tc;i++){
        String s[] = br.readLine().split(" ");
        long n = Long.valueOf(s[0].trim());
        long m = Long.valueOf(s[1].trim());

        if((m==1 && n!=2) || (m!=2 && n==1)){
            System.out.println("No");
        }

        if((m==1 && n==2) || (m==2 && n==1)){
            System.out.println("Yes");
        }

        if(m%2 ==1 && n%2==1)
            System.out.println("No");
        else
            System.out.println("Yes");
    }

What is Hamiltonian Matching?

Can anyone find the failing test case for my program above. It gave WA.
Submission link

plz someone tall me what is means of this line plz…

If N=1 or M=1, and max{N,M}>=3

@rohit1495

This means that if the matrix is a row matrix (one row and number of columns > 2)

[1 1 … 1]

or a column matrix (one column and number of rows > 2)

[

1

1

.

.

.

1

]

@ravichandrae, try n = 6, m = 1.

@tihor14, try running your code locally. It prints 2 answers for each case.

Hello @prateekg603

" assert(n >= 1 && n <= 1000000000000000000LL); " Why is this included when we know for sure that the input lies in this range?

Thanks & Regards
Amaresh

What is wrong with my code? i am getting wrong answer, even though offline execution shows my code is correct

import java.util.*;
import java.io.*;
public class Main {
	public static void main(String args[]) {
	try
	{
		int numberOfTestCase;
		Scanner input= new Scanner(System.in);
		numberOfTestCase=Integer.parseInt(input.nextLine());
		for(int loop=1;loop<=numberOfTestCase;loop++)
		{
			int row,column;
			row=Integer.parseInt(input.next());
			column=Integer.parseInt(input.next());
			if(row%2!=0&&column%2!=0)
			{
				if((row==1&&column==1))
				{
					System.out.println("Yes");
				}
				else
					System.out.println("No");
			}
			else
			{
				if((row==1&&column!=2)||(column==1&&row!=2))
					System.out.println("No");
				else
					System.out.println("Yes");
			}
		}
		input.close();
	}
	catch(Exception e)
	{
		return;
	}
}
}

Why will be the answer or 3 3 be No

Why will be the answer for 3 3 be No

for the case n=1 and m>2, flag should be zero. Similarly the opposite case.

1 Like

gotcha!its accepted now.thanks@lickecs for your effort.

1 Like

i’d be very sad if this was your best submitted code during the contest. change “YES” to “Yes” and “NO” to “No”. :stuck_out_tongue:

Unfortunately, this was.I don’t know how I missed that.

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.