Under construction

Still being built. Things may change

Jail or Joyride

Time limit4sMemory limit1024 MB

Summary
Police chase teenagers who jump to the farthest reachable junction whenever the police arrive. Find the minimum distance for guaranteed capture, or impossible.
Level

Hard9 of 10

Topics
Graph, Shortest path, Game theory
Solved
No attempts yet

Problem

A group of teenagers has stolen a fast sports car for a Saturday night joyride. The local police department has only one car available to catch them red-handed and send them to a youth detention center.

The city is made up of junctions and bidirectional roads, each with a fixed length. The teenagers stay at a junction until just before the police car arrives at that junction. At that moment, they want to reach a junction as far as possible from their current location without using the road the police car is on. They quickly check a map to find every junction in the city that is reachable without using the road the police car is on. They then use their satnav system to determine the distance to each of these junctions and randomly choose one of the farthest junctions. The satnav system does not know where the police car is, so it does not take the police car into account when computing distances. The sports car then drives instantly to that junction along any route that does not pass by the police car, leaving the police behind. The teenagers wait there until the police car makes a new approach. The only way for the police to catch them is to approach them while they are in a dead end, that is, a junction with only one road connected to it. Figure J.1 shows how the police can catch the teenagers in the first sample case.

Figure J.1: Possible movements of the police (P) and teenagers (T) in the first sample case. The police movement (solid blue arrows) takes time according to edge lengths, while the teenagers' movement (dashed red arrows) is instant.

Since time is precious for the police, they need you to find out whether it is possible to catch the joyriders with absolute certainty. If so, what is the minimum distance they need to drive to be guaranteed to catch the youngsters, assuming the police uses an optimal strategy?

Input

The input consists of:

  • One line containing four integers: nn (2≤n≤3002 \leq n \leq 300), the number of junctions; mm (1≤m≤n(n−1)21 \leq m \leq \frac{n(n-1)}{2}), the number of roads; pp (1≤p≤n1 \leq p \leq n), the initial position of the police car; and tt (1≤t≤n1 \leq t \leq n, t≠pt \neq p), the initial position of the group of teenagers.
  • Then mm lines follow, each containing three integers aa, bb, and ℓ\ell (1≤a,b≤n1 \leq a, b \leq n, a≠ba \neq b, and 1≤ℓ≤1091 \leq \ell \leq 10^9), indicating a road between junctions aa and bb with length ℓ\ell.

There is at most one road between every pair of junctions, and any junction can reach any other junction using the roads.

Output

If it is possible to catch the teenagers with absolute certainty, output the minimum distance the police car must cover to achieve this. Otherwise, output impossible.

Examples2

  1. Example 1

    Input
    5 5 1 2
    1 2 2
    2 3 2
    3 4 3
    4 5 1
    2 5 2
    
    Expected output
    10
    
  2. Example 2

    Input
    5 5 1 3
    1 2 2
    2 3 2
    3 4 3
    4 5 1
    2 5 2
    
    Expected output
    impossible