#P3657. [USACO17FEB] Why Did the Cow Cross the Road II P
[USACO17FEB] Why Did the Cow Cross the Road II P
Description
Farmer John raises breeds of cows, numbered from to . Some breeds get along well with others; it turns out that if two breeds are numbered , then when , these two breeds can get along, otherwise they cannot.
A long road runs through the farm. There are pastures on the left side of the road (each occupied by exactly one breed), and pastures on the right side of the road (each occupied by exactly one breed). To help the cows safely cross the road, Farmer John wants to paint some crosswalks (cow-walks?) on the road, subject to the following conditions:
- Each crosswalk connects a pasture on the left to a pasture on the right.
- The breeds of the two connected pastures must get along.
- No two crosswalks may intersect in the middle of the road.
- Each pasture can be connected to at most one crosswalk.
You need to help FJ determine the maximum possible number of crosswalks.
Input Format
The first line contains an integer ().
The next lines each contain an integer , representing the breed in the -th pasture on the left side of the road.
The next lines each contain an integer , representing the breed in the -th pasture on the right side of the road.
Output Format
Output the maximum number of crosswalks.
6
1
2
3
4
5
6
6
5
4
3
2
1
5
Hint
It is guaranteed that both and are permutations of to .
Translated by ChatGPT 5
京公网安备 11011102002149号