Alice and Bob are playing a board game. They have boards and two arrays and of length . The value of each cell in the row and row is . Alice asks questions to Bob. In each question, Alice provides two cells and . She asks the following questions to Bob:
Are there any paths from to that contains the same parity as and .
Input format
For each query, if there exists a path (for example, ) from to that contains the same parity as and , then print YES. If the parity of A and B are different, then print NO.
Input
Are there any paths from to that contains the same parity as and .
Input format
- First line: An integer denoting the length of arrays
- Second line: integers with representing array
- Third line: integers with representing array
- Fourth line: An integer denoting the number of test cases
- For each test case:
- First line: Two integers denoting the row and the column of
- Second line: Two integers denoting the row and the column of
For each query, if there exists a path (for example, ) from to that contains the same parity as and , then print YES. If the parity of A and B are different, then print NO.
Input
3 0 3 1 1 5 3 2 2 1 3 3 3 1 1 3Output
YES NO
Solution
import java.util.*;
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner s = new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n+1];
int b[]=new int[n+1];
for(int i=1;i<=n;i++)
a[i]=s.nextInt();
for(int i=1;i<=n;i++)
b[i]=s.nextInt();
int t=s.nextInt();
for(int j=0;j<t;j++)
{
int x=s.nextInt();
int y=s.nextInt();
int xx=s.nextInt();
int yy=s.nextInt();
int an=a[x]+b[y];
int aa=a[xx]+b[yy];
if((an|1)==(aa|1))
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
if you have any problem in this code, take a screen shot and contact with Rishab Chaubey.
Post a Comment