#P4757. [CERC2014] Parades

[CERC2014] Parades

题目描述

In The City of Eternal Festivities, there are nn street junctions and n1n-1 bidirectional streets,each street connecting two of the junctions. Between every two junctions, there is exactly one (direct or indirect) path connecting them. No junction is an endpoint for more than 10 streets.

Every 13th of September (the 256th day of the year), there are many festivities going on in The City. In particular, the citizens want to organize mm parades. The parade number ii starts at junction uiu_i and ends at viv_i, following the unique path between the endpoints.

As the mayor of The City, you are responsible for citizens’ safety. Therefore you decreed that no two parades are ever allowed to use the same street, though they can have common junctions,or even common endpoints.

To appease your citizens, try to organize as many parades as possible, without breaking the safety regulations.

输入格式

The first line of input contains the number of test cases TT. The descriptions of the test cases follow:

The first line of each test case contains a single integer: the number of junctions n(2n1000)n(2 \le n \le 1000). Each of the next n1n - 1 lines contains two integers a,b(1abn)a, b(1 \le a ≠ b \le n), denoting that junctions aa and bb are connected by a street. Each junction has at most 1010 streets leaving it.

The next line contains a single integer: the number of planned parades m,0m(2n)m, 0 \le m \le (_2^n).

Each of the next mm lines contains two integers ui,vi(1uivin)u_i, v_i (1 \le u_i ≠ v_i \le n),meaning that a parade is planned to start at junction uiu_i, and finish at junction viv_i. No two parades share both endpoints.

输出格式

For each test case, output one line containing the largest number of parades that can be organized with no street used by more than one parade.

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