Logo
(追記) (追記ここまで)

10502번 - Parades 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 256 MB128312825.225%

문제

In The City of Eternal Festivities, there are n street junctions and n−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 m parades. The parade number i starts at junction ui and ends at vi, 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 T. The descriptions of the test cases follow:

The first line of each test case contains a single integer: the number of junctions n (2 ≤ n ≤ 1000). Each of the next n − 1 lines contains two integers a, b (1 ≤ a ≠ b ≤ n), denoting that junctions a and b are connected by a street. Each junction has at most 10 streets leaving it. The next line contains a single integer: the number of planned parades m, 0 ≤ m ≤ n(n+1)/2.

Each of the next m lines contains two integers ui, vi (1 ≤ ui ≠ vi ≤ n), meaning that a parade is planned to start at junction ui, and finish at junction vi. 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

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

예제 출력 1

2

힌트

출처

ICPC > Regionals > Europe > Central European Regional Contest > CERC 2014 A번

Contest > Open Cup > 2014/2015 Season > Stage 4: Grand Prix of Europe C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /