Boat Commuter
InterviewTime limit2sMemory limit1024 MB
Given a chronological log of pier tap events, compute each travel card's total fare, where an unfinished trip or a trip starting and ending at the same pier costs 100 pounds.
- Level
Easy3 of 10
- Topics
- Simulation, Array
- Solved
- No attempts yet
Problem
The Bulgarian city of Nodnol runs a boat service to ferry its residents between the trendy areas where they live and the large metallic structures where they work on the next recession.
TFN (Transport For Nodnol) has issued travel cards, known affectionately as "Retsyo", numbered from to . Each pier has a card terminal where passengers tap "in" when starting a trip and tap "out" when finishing it.
Since each pier has only one card terminal, passengers use the same device to tap in and to tap out.
The cost of a trip depends on the distance travelled:
- if the trip started at pier and finished at pier (), its cost is pounds;
- if the trip started somewhere but was not finished with a tap out, it costs £100;
- if the trip started and finished at the same pier, it also costs £100, because it is treated as an attempt to game the system.
You are given a sequence of tapping events. For each event, the pier and the card number are recorded. Determine how much the transport authority should charge each card.
Input
- One line containing three integers: the number of piers , the number of travel cards , and the number of events (, ).
- further lines, each describing a tap event in chronological order.
- The -th event is described by two integers and (, ).
Output
Output integers separated by spaces. The -th integer is the total charge for the -th card.