#FW0000093. Chuyến tham quan các tuyến đường (Sightseeing Tour)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chuyến tham quan các tuyến đường (Sightseeing Tour)
Sightseeing Tour
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given an undirected weighted graph and multiple queries, each query specifies required edge IDs. Starting at vertex and ending at vertex , traverse each required edge at least once, in either direction. Any roads may be used additionally. Find the minimum length for each query.
Input
First and indexed edges . Next integer ; each query contains followed by distinct required edge IDs.
Output
Print the minimum total distance per query, or -1 if impossible.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
3 3
1 2 2
2 3 3
1 3 12
1
1 2
Output
5
Explanation
Required edge 2 joins vertices 2 and 3 with length 3. Go from 1 to 2 along edge 1 of length 2, then cross the required edge to vertex 3. Total distance .