#abc327d. D - Good Tuple Problem

D - Good Tuple Problem

Score : 400400 points

问题描述

一对长度为 MM 的由不超过 NN 的正整数组成的序列,记作 $(S, T) = ((S_1, S_2, \dots, S_M), (T_1, T_2, \dots, T_M))$,如果满足以下条件,则称其为 一对良好的序列

  • 存在一个由 0011 组成的长度为 NN 的序列 X=(X1,X2,,XN)X = (X_1, X_2, \dots, X_N),满足以下条件:
    • 对于每个 i=1,2,,Mi=1, 2, \dots, M,有 XSiXTiX_{S_i} \neq X_{T_i}

现给定一个由不超过 NN 的正整数组成的长度为 MM 的序列对:$(A, B) = ((A_1, A_2, \dots, A_M), (B_1, B_2, \dots, B_M))$。若 (A,B)(A, B) 是一对良好的序列,则输出 Yes;否则,输出 No

约束条件

  • (1N,M2×105( 1 \leq N, M \leq 2 \times 10^5 )
  • (1Ai,BiN)( 1 \leq A_i, B_i \leq N )
  • 所有输入值均为整数。

输入格式

输入通过标准输入给出,格式如下:

N M
A_1 A_2 ... A_M
B_1 B_2 ... B_M

输出格式

如果 ((A, B)) 是一个好的序列对,输出 Yes;否则,输出 No

样例输入 1

3 2
1 2
2 3

样例输出 1

Yes

如果设置 ( X = (0, 1, 0) ),那么 ( X ) 是一个长度为 ( N ) 的由 0 和 1 组成的序列,且满足 ( XA1XB1X_{A_1} \neq X_{B_1} ) 和 ( XA2XB2X_{A_2} \neq X_{B_2} )。
因此,((A, B)) 满足好的序列对的条件。

样例输入 2

3 3
1 2 3
2 3 1

样例输出 2

No

不存在满足条件的序列 ( X ),因此 ((A, B)) 不是一个好的序列对。

样例输入 3

10 1
1
1

样例输出 3

No

样例输入 4

7 8
1 6 2 7 5 4 2 2
3 2 7 2 1 2 3 3

样例输出 4

Yes

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

A pair of sequences of length MM consisting of positive integers at most NN, $(S, T) = ((S_1, S_2, \dots, S_M), (T_1, T_2, \dots, T_M))$, is said to be a good pair of sequences when (S,T)(S, T) satisfies the following condition.

  • There exists a sequence X=(X1,X2,,XN)X = (X_1, X_2, \dots, X_N) of length NN consisting of 00 and 11 that satisfies the following condition:
    • XSiXTiX_{S_i} \neq X_{T_i} for each i=1,2,,Mi=1, 2, \dots, M.

You are given a pair of sequences of length MM consisting of positive integers at most NN: $(A, B) = ((A_1, A_2, \dots, A_M), (B_1, B_2, \dots, B_M))$. If (A,B)(A, B) is a good pair of sequences, print Yes; otherwise, print No.

Constraints

  • 1N,M2×1051 \leq N, M \leq 2 \times 10^5
  • 1Ai,BiN1 \leq A_i, B_i \leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \dots AMA_M

B1B_1 B2B_2 \dots BMB_M

Output

If (A,B)(A, B) is a good pair of sequences, print Yes; otherwise, print No.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

Yes

If we set X=(0,1,0)X=(0,1,0), then XX is a sequence of length NN consisting of 00 and 11 that satisfies XA1XB1X_{A_1} \neq X_{B_1} and XA2XB2X_{A_2} \neq X_{B_2}.
Thus, (A,B)(A, B) satisfies the condition of being a good pair of sequences.

Sample Input 2

3 3
1 2 3
2 3 1

Sample Output 2

No

No sequence XX satisfies the condition, so (A,B)(A, B) is not a good pair of sequences.

Sample Input 3

10 1
1
1

Sample Output 3

No

Sample Input 4

7 8
1 6 2 7 5 4 2 2
3 2 7 2 1 2 3 3

Sample Output 4

Yes

update @ 2024/3/10 01:51:10