Problem p01975 - Generation 3

Orig Description

B: Mapping
Problem
AOR Ika-chan created a mapping $f:S\rightarrow S$ for a set $S=\{a_1, ..., a_N\}$, where $f(a_i)=b_i$. For any element $x$ in set $S$, determine whether all mappings $g,h:S\rightarrow S$ that satisfy $g(f(x))=h(f(x))$ also satisfy  $g(x)=h(x)$. If they do not satisfy this condition, provide a counterexample.
Constraints:
$1 \le N \le 10^5$
$1 \le a_i,b_i \le N$
$a_i \neq a_j \ (i \neq j)$
All input is integers
Input:
$N$
$a_1 \cdots a_N$
$b_1 \cdots b_N$
Output:
If the condition is satisfied, output
Yes
If the condition is not satisfied, provide a counterexample $g(a_i) = c_i, h(a_i) = d_i$, and output
No
$c_1 \cdots c_N$
$d_1 \cdots d_N$
Output a newline character at the end.
Sample
Sample Input 1
5
1 2 3 4 5
3 4 2 5 1
Sample Output 1
Yes
Sample Input 2
5
1 2 3 4 5
3 4 3 5 1
Sample Output 2
No
3 1 5 2 4
3 2 5 2 4

Extracted Specification

An integer N (1 ≤ N ≤ 10^5), representing some quantity or size.
A list of integers A of size N, where each integer is between 1 and N, and all integers in the list are unique.
A list of integers B of size N, where each integer is between 1 and N.

### Example Input:

```
5
1 2 3 4 5
3 4 2 5 1
```

### Function Signature:
Write a function f(N, A, B) that takes in the input. 
def f(N: int, A: List[int], B: List[int]): 
    ''' 
    N: an integer 
    A: a list of integers
    B: a list of integers
    '''

Test Case Generator

Certainly! Here is a test case generator for the given problem statement "B: Mapping":

```python
import random

def tcgen():
    N = random.randint(1, 10**5)
    
    # Generate a permutation of 1 to N for both a and b
    a = list(range(1, N + 1))
    b = a[:]
    random.shuffle(b)
    
    return N, a, b

# Example usage:
N, a, b = tcgen()
print(N)
print(' '.join(map(str, a)))
print(' '.join(map(str, b)))
```

This generator creates a random test case as follows:
1. Selects a random integer \( N \) within the given constraints.
2. Creates a list \( a \) which is a permutation of integers from 1 to \( N \).
3. Creates a list \( b \) which is another permutation of the same integers.

The generator ensures that \( a_i \neq a_j \) and \( b_i \neq b_j \) by creating permutations of the set \( \{1, ..., N\} \).

You can use this generator to create various test cases for the problem "B: Mapping". The generated values are printed in a format that can be directly used as input for the problem.

Extract Arguments

# def f(N, A, B):
#     ....

def extract_arguments(fh):
    N = int(fh.readline().strip())
    A = list(map(int, fh.readline().strip().split()))
    B = list(map(int, fh.readline().strip().split()))
    return N, A, B

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh:
#         N, A, B = extract_arguments(fh)
#         f(N, A, B)