#P3905. 道路重建
道路重建
Description
Once, in a kingdom, there were roads connecting cities, and between any two cities there was at most one direct road. After a severe war, roads were destroyed. The king wants to repair the country's road system. Now, traffic between two important cities and is interrupted, and the king hopes to restore the connection between these two cities as soon as possible. Your task is to repair some roads to restore the connection between and , while minimizing the total length of the repaired roads.
Input Format
The first line contains an integer , representing the number of cities. These cities are numbered from to .
The second line contains an integer , representing the number of roads.
Each of the next lines contains integers , indicating that there is a road of length directly connecting city and city .
The next line contains an integer , representing the number of roads that were destroyed after the war. In each of the following lines, there are two integers and , indicating that the road directly connecting city and city was destroyed.
The last line contains two integers and , representing the two important cities whose traffic needs to be restored.
Output Format
Output a single integer, representing the minimal total length of roads that must be repaired to restore traffic between and .
3
2
1 2 1
2 3 2
1
1 2
1 3
1
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号