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

35074번 - Canal Crossing 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 2048 MB333100.000%

문제

To escape from the Christmas market hassle, you are planning a trip to Venice to see its beautiful canals and its many bridges. Unfortunately, you do not seem to be the only person with that plan, and Venice recently decided to charge for that pleasure. Therefore, you decide that crossing each bridge once is enough for you. Fortunately, every place can be reached from any other using only streets, without crossing any bridges. Interestingly, there is exactly one way to reach any other place using only streets.

After you gathered all this knowledge, now all that is left is to plan a trip that crosses each bridge exactly once. To keep things interesting, you also want to use each street at most once. What is the length of the shortest possible trip? Note that your tour can start at any place you choose, but it has to end where it starts.

Figure C.1: Illustration of Sample Input 1 with a tour of length 45ドル$.

입력

The input consists of:

  • One line with an integer $n$ (3ドル\leq n\leq 10^5$), the number of places in Venice.
  • $n-1$ lines, each with three integers $a,ドル $b,ドル and $w$ (1ドル\leq a,b\leq n,ドル $a \neq b,ドル 1ドル\leq w\leq10^6$), the starting and ending place of each street and its length.
  • One line with an integer $m$ (1ドル\leq m\leq5\cdot10^5$), the number of bridges in Venice.
  • $m$ lines, each with two integers $a$ and $b$ (1ドル\leq a,b\leq n,ドル $a \neq b$), the places where each bridge starts and ends.

Bridges are short, and thus have length zero.

It is guaranteed that every place can be reached from any other place without using any bridges. Further, no bridge connects two places which are directly connected by a street, and all bridges are between distinct pairs of places. Lastly, it is guaranteed that at least one tour exists that crosses each bridge exactly once and uses every street at most once.

출력

Output the length of the shortest tour that crosses all bridges and uses each street at most once.

제한

예제 입력 1

8
5 1 8
5 2 1
2 7 2
4 2 4
3 1 16
1 6 32
8 4 64
3
7 4
3 6
3 7

예제 출력 1

45

예제 입력 2

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

예제 출력 2

0

노트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2025 C번

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

출처

대학교 대회

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

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