#P2078. 朋友
朋友
Description
The employees of each company share one characteristic: everyone in the same company is of the same sex.
Company A has employees with friend pairs. Company B has employees with friend pairs. Friends of friends are also friends.
Each friend pair is given as two integers , indicating the IDs of the two friends are and . Male IDs are positive numbers, and female IDs are negative numbers. Xiao Ming’s ID is , and Xiao Hong’s ID is .
It is known that Xiao Ming and Xiao Hong are friends. Please write a program to find the maximum total number of couples that can be formed between the two companies via people known through Xiao Ming and Xiao Hong (including themselves).
Input Format
The first line contains space-separated positive integers .
Then follow lines, each containing two positive integers .
Then follow lines, each containing two negative integers .
Output Format
Output a single positive integer on one line, representing the maximum total number of couples that can be formed via people known through Xiao Ming and Xiao Hong (including themselves).
4 3 4 2
1 1
1 2
2 3
1 3
-1 -2
-3 -3
2
Hint
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号