포럼
문제 ICPC00231

C. Canal Crossing

설명

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.

제약
입력 형식

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
출력
45
예제 2
입력
5
1 3 1
2 1 3
1 4 3
5 1 7
4
3 2
4 5
2 5
3 4
출력
0
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2025

평가 및 의견

C. Canal Crossing

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

C. Canal Crossing

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8