Meeting Point
InterviewTime limit0.5sMemory limit1024 MB
Given a weighted road graph, list every crossroad X where the shortest distance from P to X is twice the P-to-G distance and every shortest path to X passes through G.
- Level
Medium6 of 10
- Topics
- Shortest path, Graph, DFS
- Solved
- No attempts yet
Problem
Your friend Pedro always gets very excited for group activities. In his excitement, he runs so fast to the meeting point that he gets tired before arriving.
One day, you decided to gather data on this phenomenon. You noticed that he consistently gets tired exactly at the midpoint of his route. In other words, he gets tired when he has traveled half the distance he was going to travel.
Your city has crossroads identified by distinct integers from to , and two-way roads. Each road has a length and connects a specific pair of crossroads. There is a path in the city between every pair of crossroads. The distance between two crossroads is the length of a shortest path between them.
Pedro lives at crossroad , and your group of friends decided to meet at crossroad later today. You devised the following plan so that Pedro arrives on time. You will tell him a misleading meeting point so that he gets tired exactly at . For this plan to work, crossroad must belong to every path that Pedro could take from to the misleading meeting point. For each such path, Pedro must get tired exactly at . Pedro is a good planner and would never take a path longer than needed.
Which crossroads would work as that misleading meeting point?
Input
The first line contains two integers () and (), the number of crossroads and the number of roads. Each crossroad is identified by a distinct integer from to .
The second line contains two integers and (, ), the crossroad where Pedro lives and the correct meeting point.
Each of the next lines describes a road with three integers , and (, , ), meaning there is a two-way road of length between crossroads and .
The graph is connected. There is at most one road between each pair of crossroads.
Output
Output a single line with an increasing list of integers, the crossroads that would work as the misleading meeting point. If no crossroad works, output the character * (asterisk) instead.