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