P15100 [HackerEarth] View Russian Translation
提高
题目描述

View Russian Translation

Benny is living in a big country. This country has N cities and M biderectional roads between cities. Each road is characterized by three integers - u, v and c where u and v are the cities connected by this road and c is the length of this road. There can be more than one road between two cities. There no roads connecting city to itself.

Benny has many friends. They really like to travel therefore they are not staying at home all the time. Sometimes they return to their homes or conversely leave their homes. You will be given all information about Benny's friends.

Every time when Benny gets bored she wants to visit some of her friends. She wants to find such friend that path between Benny's current city and friend's city has the minimal inconvenience.

Inconvenience of the path which consists of K edges with lengths C1, C2, ..., Ck equals to maximum number among C1, C2, ..., Ck.

You are given a graph with N cities and M biderectional roads. You have to process Q queries. Each query has on of the following types:
+ v -- means that one of Benny's friends return from the journey and is staying at city with index v.
- v -- means that one of Benny's friends leaves his home which is located in the city with index v.
? v -- means that Benny wants to visit one of her friend that the path between them has the minimal inconvenience. This friend must be at home in this moment. Benny's current location is the city with index v.

For each query of type "?" output in a single line one integer - minimal inconvenience of the path to her friend or -1 if she can not reach home of any friend.

Input format

The first line contains two integers N and M denoting the number of cities and number of roads.
Each of the next M lines contain three integers u, v, c, denoting the road between cities u and v with length c.
The next line contains a single integer Q denoting the number of queries.
The following Q lines contain descriptions of queries.
Each query consists of one character denoting the type of query, space, and the index of vertex.

Output format

For each query of type "?" output in a single line one integer - minimal inconvenience of the path to her friend or -1 if she can not reach home of any friend.

Constraints
1 ≤ N, M, Q ≤ 10^5
1 ≤ Ci ≤ 10^9
1 ≤ N, M, Q ≤ 10^3 in test data worth 20% of all points

SAMPLE INPUT
3 5
1 2 10
1 2 5
1 3 4
1 3 100
2 3 1000
10
+ 1
? 1
+ 2
? 1
- 1
? 1
? 3
+ 3
? 1
? 3

SAMPLE OUTPUT
0
0
5
5
4
0

输入格式

见题面

输出格式

见题面

样例输入
10 20 6 10 61130 9 10 10707 6 5 44869 1 4 51090 5 8 18187 1 5 84442 6 9 39334 2 4 32258 1 9 17533 4 10 44520 1 5 12675 6 3 30075 2 6 68108 3 5 12284 3 9 71460 1 5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 2 ? 8 ? 9 ? 10 + 6 ? 1 + 6 ? 9 ? 10 - 10 - 8 + 1 - 1 ? 4 - 4 - 9 + 6 + 7 + 5 + 3 ? 5 + 10 - 6 ? 2 ? 9 + 9 + 6 - 1 + 8 - 10 - 2 ? 5 ? 5 - 6 - 3 ? 6 ? 1 ? 5 + 3 + 7 + 10 - 7 + 3 + 4 + 1 + 6 + 9 + 10 - 10 - 1 + 8 ? 7 - 2 + 1 ? 1 + 7 ? 3 - 9 + 9 ? 10 + 8 - 8 + 3 - 6 - 6 + 3 - 5
样例输出
-1 -1 -1 -1 -1 -1 829750939 -1 590901981 -1 816444728 -1 708358640 612565687 841249930 811675303 600726150 600726150 537874751 600726150 -1 600726150 651665199 651665199 710867499 651665199 847459648 -1 538071653 538071653 588104101 538071653 -1 838065112 452100857 628386659 786196848 915348393 -1 628386659 457620499 654739665 -1 628386659 465076729 678025302 537874751 978043012 604791147 925425564 879449485 710867499 879449485 851079241 -1 631163730 465614277 957649055 117104486 -1 -1 -1 732465513 654739665 -1 600726150 574333874 600726150 -1 574333874 516792202 600726150 612565687 732465513 720683115 -1 547102974 750678724 839565269 589905323 547102974 0 662130608 708358640 538071653 547102974 0 -1 903008407 736562652 311112951 556930857 136878374 574333874 588104101 447540518 547102974 547102974 -1 650666942 957961405 647089168 -1 259597514 546401523 748385525 -1 -1 914903167 601363014 516792202 -1 476595370 422038734 -1 589905323 -1 823710218 -1 574333874 574333874 702934921 505115294 932804079 470597323 885716343 978043012 885716343 546401523 422038734 600726150 502553946 915348393 478678622 628386659 465614277 727671933 -1 588104101 505115294 914903167 628386659 763415164 459156821 588104101 -1 290503576 465614277 612565687 628386659 516610076 604791147 628386659 681577786 952568768 -1 310331767 590901981 713541962 -1 936590122 750678724 612565687 -1 537874751 311767454 466216192 574333874 311767454 949419417 617078960 574333874 885674375 -1 448265270 505115294 -1 749563494 537874751 417396948 628386659 559910328 547102974 490240417 795387581 628386659 879449485 411369660 -1 847459648 791586594 -1 574333874 574333874 -1 617858162 -1 -1 604791147 574333874 547102974 -1 -1 541461666 -1 600726150 310331767 -1 574333874 -1 522007359 829750939 522007359 -1 550273238 578693396 729956770 856646927 282803242 628386659 701581490 537874751 710867499 -1 839565269 -1 647361654 958579583 574333874 -1 -1 287439681 691126471 830397567 628386659 -1 600726150 708358640 600726150 -1 612565687 -1 749563494 600726150 574333874 550273238 -1 628386659 673243438 811675303 -1 -1 -1 588104101 710867499 505115294 647361654 749563494 684371603 936590122 612565687 851079241 796163075 712656622 628386659 691126471 497978721 -1 932214598 -1 647819203 160294494 547102974 547102974 622395126 750678724 628386659 -1 445108235 612565687 355367789 -1 622716133 447540518 614019084 739666612 -1 604791147 -1 -1 490240417 590901981 556067541 628386659 720295510 574333874 604791147 -1 600726150 299062375 538071653 782712879 782712879 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 725684940 574333874 783791019 749563494 505115294 604791147 582148962 -1 505115294 373521023 570039991 574333874 -1 574333874 225618424 710867499 708358640 350713893 695230428 628386659 350713893 641273240 282803242 574333874 691126471 383575600 -1 -1 885716343 885716343