Pizza Delivery
Time limit2sMemory limit512 MB
Given a directed weighted graph with source 1 and target 2, each day flips the direction of one distinct edge; report whether the shortest path distance shrinks, stays equal, or grows (or becomes unreachable).
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Dynamic programming
- Solved
- No attempts yet
Problem
Alyssa is a college student living in New Tsukuba City. Every street section in the city is one way. A social experiment starting tomorrow reverses one street section between two adjacent intersections each day. All other sections keep their direction, and the reversal is canceled the next day. On day the reversed section is section .
Alyssa orders a pizza every day from the same pizzeria. The pizza is delivered along the shortest route from the intersection with the pizzeria to the intersection with Alyssa's house.
Changing the traffic regulation may change the shortest route. Report how the experiment affects the delivery route on each day.
Input
The input consists of a single test case in the following format.
n m
a1 b1 c1
.
.
.
am bm cm
The first line contains two integers, , the number of intersections, and , the number of street sections in New Tsukuba City (, ). The intersections are numbered through and the street sections are numbered through .
The following lines contain the information about the street sections, each with three integers , , and (, , , ). Section connects two intersections with the one way direction from to and has length , and it is the section reversed on day . More than one section may connect the same pair of intersections.
The pizzeria is on intersection and Alyssa's house is on intersection . At least one route from the pizzeria to Alyssa's house exists before the experiment starts.
Output
Print lines. Line must be
HAPPYif the shortest route on day becomes shorter,SOSOif the length of the shortest route on day does not change, andSADif the shortest route on day becomes longer, or if no route from the pizzeria to Alyssa's house remains.
Alyssa does not care whether the delivery bike can go back to the pizzeria.