#P2423. [HEOI2012] 朋友圈

[HEOI2012] 朋友圈

Description

A very long time ago, there were two countries living in harmony and without worries.

The annual evaluation begins. As two peaceful countries, the one with the largest friend circle is always the most respected. So now you need to find the maximum size of a friend circle. The two countries are denoted as A and B, and their descriptions are as follows:

  • Country A: Each person has a friendliness value. For two people in Country A with friendliness values a,ba, b, if (axorb)mod2=1(a\mathbin{\mathrm{xor}} b) \bmod 2=1, then the two people are friends; otherwise they are not.
  • Country B: Each person has a friendliness value. For two people in Country B with friendliness values a,ba, b, if (axorb)mod2=0(a\mathbin{\mathrm{xor}} b) \bmod 2=0 or (aorb)(a\mathbin{\mathrm{or}} b) has an odd number of 11 bits in binary, then the two people are friends; otherwise they are not.

People between Countries A and B may also be friends. The testdata will provide the "friend" relations between A and B.

Friendship is bidirectional.

In Countries A and B, a friend circle is defined as follows: a set SS, satisfying SABS \subset A \cup B, such that for all i,jSi,j \in S, ii and jj are friends.

Input Format

This problem contains multiple test cases.

  • The first line contains an integer TT, the number of test cases.
  • For each test case:
    • Line 1 contains 33 integers A,B,MA, B, M, the number of people in Country A, the number of people in Country B, and the number of cross-country friend pairs, respectively.
    • Line 2 contains AA integers aia_i, the friendliness values of the ii-th person in Country A.
    • Line 3 contains BB integers bib_i, the friendliness values of the ii-th person in Country B.
    • Lines 44 to 3+M3+M: each line contains two integers x,yx, y, indicating that the xx-th person in Country A and the yy-th person in Country B are friends.

Output Format

Output TT lines, each containing an integer, the maximum size of a friend circle.

1
2 4 7
1 2
2 6 5 4
1 1
1 2
1 3
2 1
2 2
2 3
2 4
5

Hint

Sample Explanation

The maximum friend circle contains the 11-st and 22-nd people of Country A and the 11-st, 22-nd, and 33-rd people of Country B.

Constraints

For 100%100\% of the testdata, 1T61 \le T \le 6, 1ai,bi<2311 \le a_i, b_i < 2^{31}.

There are two categories of testdata, and all test points satisfy at least one of the following:

  • Category 1: 1A2001 \le A \le 200, 1B2001 \le B \le 200.
  • Category 2: 1A101 \le A \le 10, 1B30001 \le B \le 3000.

Translated by ChatGPT 5