GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 6 May 2022

Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022 

C. Where is the Pizza?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While searching for the pizza, baby Hosssam came across two permutations a and b of length n.

Recall that a permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

Solution Click Below:-  CLICK HERE

Baby Hosssam forgot about the pizza and started playing around with the two permutations. While he was playing with them, some elements of the first permutation got mixed up with some elements of the second permutation, and to his surprise those elements also formed a permutation of size n.

Prof. Slim Codeforces Solution | Codeforces Problem Solution 2022

Dorms War Codeforces Solution | Codeforces Problem Solution 2022

Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022

Very Suspicious Codeforces Solution | Codeforces Problem Solution 2022

Hemose on the Tree Codeforces Solution | Codeforces Problem Solution 2022

Jee, You See? Codeforces Solution | Codeforces Problem Solution 2022

Specifically, he mixed up the permutations to form a new array c in the following way.

  • For each i (1in), he either made ci=ai or ci=bi.
  • The array c is a permutation.

You know permutations ab, and values at some positions in c. Please count the number different permutations c that are consistent with the described process and the given values. Since the answer can be large, print it modulo 109+7.

It is guaranteed that there exists at least one permutation c that satisfies all the requirements.

Input

The first line contains an integer t (1t105) — the number of test cases.

The first line of each test case contains a single integer n (1n105) — the length of the permutations.

The next line contains n distinct integers a1,a2,,an (1ain) — the first permutation.

The next line contains n distinct integers b1,b2,,bn (1bin) — the second permutation.

The next line contains n distinct integers d1,d2,,dn (di is either 0ai, or bi) — the description of the known values of c. If di=0, then there are no requirements on the value of ci. Otherwise, it is required that ci=di.

It is guaranteed that there exists at least one permutation c that satisfies all the requirements.

It is guaranteed that the sum of n over all test cases does not exceed 5105.

Output

For each test case, print the number of possible permutations c, modulo 109+7.

Join Now for Solution:- 

No comments:

Post a Comment