You got the once-in-a-lifetime chance to go to Tokyo right now! As Tokyo is a large city, you've split it into
In order to properly plan out your trip, you need to estimate how long it would take to go from certain areas to area
To ensure the success of your trip, write a program that supports
1 u
: A previously uncrowded area becomes crowded.2 u
: You need to determine the minimum possible expected travel time from area to area in the current state of all the areas.
Constraints
For all events,
Subtask 1 [30%]
All type 1
events occur before all type 2
events.
Subtask 2 [70%]
No additional constraints.
Input Specification
The first line contains
The next
The next
Output Specification
For each type 2
event, output the answer (in seconds) on a new line.
Sample Input
7 7
1 2 4
1 3 3
2 4 2
3 5 1
3 6 3
6 7 2
2 4
1 3
1 6
1 4
2 7
1 1
2 1
Sample Output
6
24
0
Comments