All Tracks Algorithms Graphs Shortest Path Algorithms Problem

Sherlock and Travelling
Tag(s):

Medium

Problem
Editorial
Analytics

Sherlock loves to travel! This time, he is touring the city of London with Watson. Sherlock is in a playful mood today so he throws a challenge to Watson-
Given two cities $$A$$ and $$B$$, Sherlock will take the shortest path between the cities to travel. He also has a magic spell which destroys all the roads occurring in that path. Now, he asks Watson to tell him the shortest path from $$A$$ to $$B$$ in the new graph formed if there exists a path, or else print -1.

Input Format
First line contains two space separated integers $$N$$ and $$M$$, the number of cities and number of roads respectively.
Second line contains integers $$A$$ and $$B$$.
Next $$M$$ lines contains three space separated integers $$u$$, $$v$$, $$w$$, denoting there is a road between cities $$u$$ and $$v$$ with length $$w$$.

Output Format
Output the answer to the challenge posted by Sherlock.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic, Kotlin

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

School of Engineering, CUSAT

Challenge Name

221B Baker Street: Code for Watson

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications