#FW0000103. Nguyên liệu làm bánh (Ingredients)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nguyên liệu làm bánh (Ingredients)
Ingredients
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Two friends start in different cities. There are stores each supplying a different needed ingredient. Every store must be visited by at least one friend, who need not return home. Minimize the sum of travel distances over both friends in the undirected road network.
Input
First and undirected roads with zero-based vertices. Then and the store IDs, followed by two starting cities .
Output
Print the minimum total distance or -1.
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 2
0 2 3
1 2 4
1
2
0 1
Output
3
Explanation
The sole ingredient is at city 2. The first friend can reach it from city 0 at cost 3, versus cost 4 from city 1. Only one needs to visit and no return is needed, giving .