12-Amaliy ish Mavzu: Bog’langan graflarda marshrutlar, ularni narxi(masofasi) bo’yicha baholash. Xasis algortimlar. Eng qisqa marshrutlarni aniqlash algoritmi. Uni variantlar soni bo’yicha xajmini baholash


Download 165.04 Kb.
bet6/6
Sana18.06.2023
Hajmi165.04 Kb.
#1594697
1   2   3   4   5   6
Bog'liq
12 amaliyot Bog’langan graflarda marshrutlar Xasis algoritmlar Eng

input

output

1 100
4
0 0
1 0
9 0
9 9
1 2
1 3
2 4
0 0
10 10
10 0

2.6346295
4 4 2 1 3

4-Topshiriq
The world is in danger! Awful earthquakes are detected all over the world. Houses are destroyed, rivers overflow the banks, it is almost impossible to move from one city to another. Some roads are still useful, but even they became too steep because of soil movements.
Fortunately, engineer Ivan has a car, which can go well uphill and downhill. But there are different gear-modes for movement up and down, so during the driving you have to change gear-modes all the time. Also engineer Ivan has a good friend –– geologist Orlov. Together they are able to invent a plan for world saving. But, unfortunately, geologist Orlov lives in another town.
Ivan wants to save the world, but gear-box in his car started to wear out, so he doesn’t know, how long he will be able to use it. Please help Ivan to save the world. Find a route to the Orlov's town, such that Ivan will have to change gear-modes as few times as possible. In the beginning of the way Ivan can turn on any of gear-modes and you don't have to count this action as a changing of gear-mode.

Input


There are two positive integer numbers n and m in the first line, the number of towns and roads between them respectively (2 ≤ n ≤ 10 000; 1 ≤ m ≤ 100 000). Next m lines contain two numbers each — numbers of towns, which are connected by road. Moreover, the first is the town, which is situated below, from which you should go uphill by this road. Every road can be used for traveling in any of two directions. There is at most one road between any two cities. In the last line there are numbers of two cities, in which Ivan and geologist Orlov live, respectively. Although the majority of roads were destroyed, Ivan knows exactly, that the way to geologist Orlov's city exists.

Output


Output the smallest number of gear-modes changes on the way to Orlov's city.

Samples


input

output

3 2
1 2
3 2
1 3

1

3 3
1 2
2 3
3 1
1 3

0



Download 165.04 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling