RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0583

Cycle Correspondence

Gold I 골드 I
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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, 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.

Problem credits: Benjamin Qi

제약

SCORING

  • Inputs 4-5: \(N \le 8\)
  • Inputs 6-8: \(N \le 5000\)
  • Inputs 9-15: No additional constraints

Problem credits: Benjamin Qi

입력 형식

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
출력
6
설명

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

예제 2
입력
6 3
1 2 3
4 5 6
출력
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
출력
4
설명

Annabelle and Bessie could have assigned labels \(2,3,4,6\) to the same barns.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2023-2024 > December > Silver

태그

평가 및 의견

Cycle Correspondence

개요
출제자 난이도 Gold I 골드 I 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Cycle Correspondence

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8