Yoshirin and Micchi will spend their Golden Week vacation in Taiwan. However, their vacation plan has not been completed, because they couldn't stay serious when discussing it. Now they need a trip recommendation system to plan their itineraries. Yoshirin and Micchi have made a wish list about tourist attractions they want to visit. Each tourist attraction is scored by their preference from 1 to 5. To save time, they hope to spend less time traveling among tourist attractions. Also, they prefer popular trip itineraries, so they will visit the tourist attractions base on the constant tourist flow. Please build a trip recommendation system to help Yoshirin and Micchi.
In the system, a map will be represented as a graph, in which the nodes stand for the places listed by the user, and the edges stand for the accesses between every two places. In other words, every node is adjacent to each other. Between every two nodes exists two edges with opposite directions. There are two kinds of graphs. The first graph is about the travel time. In this graph, the edge weights are the time consumption of people traveling from one place to another. The second graph is about the tourist flow. In real life, tourist flow records the amount of people traveling from one place to another. Here we take tourist flow as the tendency of people traveling to different places. In this graph, the edge weights are the tendency values, where higher values stand for the higher tendency that people to travel from one place to another.
The system is supposed to guide users to any places with the optimal path in terms of either travel time or tourist flow. Unfortunately, some places are closed due to the pandemic situation recently. The places that have been closed should not be recommended to the users.
The system should help users find an optimal path given the origin and destination. When concerning the travel time, the path that costs the least time will be optimal. When concerning the tourist flow, the path that is the most possible to be taken will be optimal. You can regard tourist flow as a kind of probability. Please see the hint. If there are multiple optimal paths, first, choose the path with the highest sum of preference scores as the result. If there are still multiple optimal paths with the same total preference scores, choose the path that first leads to the place with the smallest index. Please see the figure below.
The system will accept 5 kinds of instructions, described as follows.
Assign a place as the origin of the traveling itinerary. The origin will not change until we reset it.
Mark the state for a set of places with “open” or “close”. If a place is open, that place can be visited; otherwise, that place cannot be visited. All the places are open in the beginning. The states of the places will not change even though the origin is reset (SET_ORIGIN %PLACE_NAME).
Parameters:
Example:
Choose a place as the destination of the trip. In terms of the assigned consideration, find the optimal path.
Choose a place as the destination of the trip. Decide a number K (2≦K≦100), which is the maximum number of stops the user wants to visit. The origin is the first stop and the destination is the last stop. Find the locally optimal path in terms of the assigned consideration. If the destination cannot be accessed within K places, there is no such path.
Stop receiving instructions.
The following elements will appear in order.
N lines of place information
%PLACE_INDEX %PLACE_NAME %PLACE_PS
%PLACE_INDEX: index of the place, from 0 to N-1 in order
%PLACE_NAME: places' name represented with a string
%PLACE_PS: users' preference score for the place
An N*N matrix contains integer values
An N*N matrix contains double values
Several instructions
According to the order in the instruction, for each place that we try to mark:
Print "End of instructions".
A new line is required at the end of each instruction output.