#646
Unrated
Cycle Correspondence
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John has NN barns (3N51053\le N\le 5\cdot 10^5), of which KK (3KN3\le K\le N) distinct pairs of barns are connected.

First, Annabelle assigns each barn a distinct integer label in the range [1,N][1,N], and observes that the barns with labels a1,,aKa_1,\dots,a_K are connected in a cycle, in that order. That is, barns aia_i and ai+1a_{i+1} are connected for all 1i<K1\le i<K, and barns aKa_K and a1a_1 are also connected. All aia_i are distinct.

Next, Bessie also assigns each barn a distinct integer label in the range [1,N][1,N] and observes that the barns with labels b1,,bKb_1,\dots,b_K are connected in a cycle, in that order. All bib_i are distinct.

Some (possibly none or all) barns are assigned the same label by Annabelle and Bessie. Compute the maximum possible number of barns that are assigned the same label by Annabelle and Bessie.

입력

The first line contains NN and KK.

The next line contains a1,,aKa_1,\dots, a_K.

The next line contains b1,,bKb_1,\dots, b_K.

출력

The maximum number of fixed points.

예제 입력 1

6 3
1 2 3
2 3 1

예제 출력 1

6

예제 입력 2

6 3
1 2 3
4 5 6

예제 출력 2

0

예제 입력 3

6 4
1 2 3 4
4 3 2 5

예제 출력 3

4

점수

Inputs 4-5: N8N \le 8Inputs 6-8: N5000N \le 5000Inputs 9-15: No additional constraints

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.