Cycle Correspondence
시간 제한2초메모리 제한1024 MB
두 사람이 같은 K개의 헛간으로 이루어진 순환을 각자 다른 번호로 지정했을 때, 두 번호가 일치하는 헛간 수의 최댓값을 구한다.
문제
Farmer John has barns (), of which () distinct pairs of barns are connected.
First, Annabelle assigns each barn a distinct integer label in the range , and observes that the barns with labels are connected in a cycle, in that order. That is, barns and are connected for all , and barns and are also connected. All are distinct.
Next, Bessie also assigns each barn a distinct integer label in the range and observes that the barns with labels are connected in a cycle, in that order. All 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 and .
The next line contains .
The next line contains .
출력
The maximum number of fixed points.