#P10930. 异象石
异象石
Problem Description
Adera is a puzzle game in the Microsoft Store.
The anomalous stone is a guide that allows entry into the alternate space-time in Adera, and there is a map in this alternate space-time.
On this map, there are nodes, and undirected edges connecting them.
At the beginning, there are no anomalous stones on the map. During the next moments, at each moment, one of the following three types of events will occur:
- An anomalous stone appears at some node on the map (a node that already has one will not get another).
- The anomalous stone at some node on the map is destroyed (a node without one will not be destroyed).
- The player is asked: what is the minimum total length of the set of edges needed to make all nodes that currently have anomalous stones connected.
Please answer these queries as the player.
Input Format
The first line contains an integer , representing the number of nodes.
The next lines each contain three integers , indicating that there is an undirected edge of length between node and node .
Line contains a positive integer .
The next lines each describe an event in one of the following formats:
+ xmeans an anomalous stone appears at node .- xmeans the anomalous stone at node is destroyed.?means a query asking for the minimum total length of the set of edges needed to connect all nodes that currently have anomalous stones.
Output Format
For each ? event, output an integer representing the answer.
6
1 2 1
1 3 5
4 1 7
4 5 3
6 4 2
10
+ 3
+ 1
?
+ 6
?
+ 5
?
- 6
- 3
?
5
14
17
10
Hint
Constraints: , , , .
Translated by ChatGPT 5