Atli is trying to get home, but like most days it’s raining
cats and dogs in Reykjavík. Thus he is trying to plan his route
such that he’ll minimize how wet he gets. More specifically he
has located shelters
from the rain which he can let himself dry under. He has also
located routes between
these shelters and for each route he has figured out how wet
he’ll get travelling that route. Additionally some of these
shelters will be bus stops. To get home Atli has to travel
between shelters until he gets to a bus stop, from which he can
travel all the way home. Atli will always travel home in a way
that minimizes how wet he gets along the way.
Atli isn’t always travelling from the same place and bus
stops aren’t set in stone either. Thus there will be
queries, each one
being one of three types. A query can say that a particular
shelter is now a bus stop, say that a particular shelter is no
longer a bus stop or ask for how wet Atli will get travelling
home from some particular shelter. At the start only shelter
is a bus stop.
Atli solved this problem long ago of course, but he won’t
tell anyone the solution since that would spoil the fun.
Input
The first line of the input contains two integers
, the number of shelters and , the number of
routes between them. Next there are lines, each describing a route
between two shelters. Each of those lines contains three
integers and . This means there is a route from shelter
to shelter
which makes Atli
wet from travelling
along it. Routes can be travelled in either direction and
does not change
depending on the direction. Next there is a line with an
integer , the number of queries. Finally there are
lines, each containing
two integers and . If this
means that a bus stop opens at shelter , in this case will not already be a bus stop. If
this means that
the bus stop at shelter closes, in this case will be a bus stop. Finally if
the program should
print how wet Atli gets at most when travelling home from
shelter .
It is guaranteed that it will always be possible to travel
from any shelter to any other. Furthermore there will always be
at least one working bus stop at any given time.
Output
How wet Atli gets should be printed for every query of type
.
Sample Input 1 |
Sample Output 1 |
4 5
1 2 5
1 3 4
2 3 2
2 4 3
3 4 1
9
3 2
1 4
3 2
3 3
1 3
3 3
2 1
2 4
3 1
|
4
2
1
0
4
|