eolymp
bolt
Try our new interface for solving problems
Problems

Distance betweeen the vertices

Distance betweeen the vertices

\textit{Коль Дейкстрý писать без кучи,} \textit{То тайм-лимит ты получишь...} \textit{А в совсем другой задаче} \textit{Юзай кучу Фибоначчи!} \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \textit{Спектакль преподавателей ЛКШ.июль-2007} Undirected weighted graph is given. Find the weight of the minimal path between two vertices. \InputFile The first line contains two numbers $n$ and $m~(1 \le n \le 10^5, 1 \le m \le 2 \cdot 10^5)$ --- the number of vertices and edges. Second line contains two numbers $s$ and $t~(1 \le s, t \le n, s \ne t)$ --- the numbers of the vertices the length between which you need to find. The next $m$ lines contain the description of the edges, one edge in a line. The edge number $i$ is described with three integers $b_i, e_i$ и $w_i~(1 \le b_i, e_i \le n, 0 \le w_i \le 100)$ --- the vertices connected by the edge and its weight. \OutputFile Print the weight of the minimal path between the vertices $s$ and $t$, or $-1$ if there is no such path. \includegraphics{https://static.e-olymp.com/content/45/4553e1879d5b2920b67d19be8688d1057e1ce444.gif}
Time limit 2 seconds
Memory limit 128 MiB
Input example #1
4 4
1 3
1 2 1
2 3 2
3 4 5
4 1 4
Output example #1
3