Logo
(追記) (追記ここまで)

31061번 - Cycle Correspondence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB2141229557.927%

문제

Farmer John has $N$ barns (3ドル\le N\le 5\cdot 10^5$), of which $K$ (3ドル\le K\le N$) distinct pairs of barns are connected.

First, Annabelle assigns each barn a distinct integer label in the range $[1,N],ドル and observes that the barns with labels $a_1,\dots,a_K$ are connected in a cycle, in that order. That is, barns $a_i$ and $a_{i+1}$ are connected for all 1ドル\le i<K,ドル and barns $a_K$ and $a_1$ are also connected. All $a_i$ are distinct.

Next, Bessie also assigns each barn a distinct integer label in the range $[1,N]$ and observes that the barns with labels $b_1,\dots,b_K$ are connected in a cycle, in that order. All $b_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 $N$ and $K$.

The next line contains $a_1,\dots, a_K$.

The next line contains $b_1,\dots, b_K$.

출력

The maximum number of fixed points.

제한

예제 입력 1

6 3
1 2 3
2 3 1

예제 출력 1

6

Annabelle and Bessie could have assigned the same label to every barn.

예제 입력 2

6 3
1 2 3
4 5 6

예제 출력 2

0

Annabelle and Bessie could not have assigned the same label to any barn.

예제 입력 3

6 4
1 2 3 4
4 3 2 5

예제 출력 3

4

Annabelle and Bessie could have assigned labels 2,3,4,6ドル$ to the same barns.

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2023 December Contest > Silver 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /