#P84. [CSP-S 2022] Galaxy war
[CSP-S 2022] Galaxy war
Person in Charge
Problem Description
In this round of interstellar warfare, our side has established outposts in the universe, connected by unidirectional wormholes. All wormholes that end at outpost are classified as the wormholes of outpost .
Amid the raging war, these wormholes are hard to maintain for long, and enemy attacks may come at any time. The effective enemy attacks can be divided into two categories:
- The enemy destroys a specific wormhole, which makes the two connected outposts unable to reach each other directly through this wormhole, but such an attack will not destroy the two connected outposts.
- The enemy destroys a specific outpost. Since the core technology of wormholes is concentrated at their exit, all undestroyed wormholes of this outpost will be destroyed along with it. However, the wormholes departing from this outpost will not be destroyed.
Note: Destruction only renders the wormholes unavailable, and does not eliminate their physical existence.
To fight against the enemy and maintain the connection between troops and outposts, our side has developed two types of special forces responsible for repairing wormholes:
- Type A special forces can repair a specific wormhole.
- Type B special forces can repair all damaged wormholes of a specific outpost.
Considering the characteristics of enemy attacks, our side has not stockpiled excessive strategic materials at the outposts. Therefore, an outpost is deemed available if at least one of its wormholes is repaired and in an available state.
Our side has mastered an exacting spatial characteristic. By utilizing this characteristic, our warships can teleport along wormholes to the enemy camp and launch precise strikes.
To seize the optimal time to launch a counteroffensive, the headquarters must monitor all changes on the battlefield to find a feasible moment for the counterattack. The commander-in-chief defines the following criteria:
- An outpost is able to launch a counterattack if starting from this outpost, warships can perform an infinite number of wormhole traversals by choosing an appropriate route (revisiting the same outpost or wormhole multiple times is allowed).
- To ensure the continuity of wormhole traversals and minimize the mass-energy loss when warships switch wormholes at an outpost, an outpost can achieve continuous traversal if and only if there is exactly one available wormhole departing from this outpost.
- A moment is deemed an optimal counterattack moment if all our outposts can both launch a counterattack and achieve continuous traversal.
The commander-in-chief has ordered you to promptly report whether an optimal counterattack moment is reached based on real-time battlefield information after each change.
Input Format
The first line of input contains two positive integers .
The next lines each contain two integers , representing a unidirectional wormhole departing from outpost and arriving at outpost . It is guaranteed that and no duplicate wormholes exist. All wormholes and outposts are intact initially.
The next line contains a positive integer , representing the number of operations and queries.
The next lines each represent an operation or query, starting with a positive integer indicating the type of instruction:
- If , followed by two integers : the enemy destroys the wormhole from outpost to outpost . It is guaranteed that the wormhole exists and is currently undestroyed.
- If , followed by one integer : the enemy destroys outpost . This attack has no effect if all wormholes of the outpost have already been destroyed.
- If , followed by two integers : our side repairs the wormhole from outpost to outpost . It is guaranteed that the wormhole exists and is currently destroyed.
- If , followed by one integer : our side repairs outpost . This repair has no effect if there are no destroyed wormholes belonging to the outpost.
After executing each instruction, you need to determine whether a counterattack can be launched. Output YES if possible, otherwise output NO.
Output Format
Output a total of lines. For each instruction, output the judgment result after the execution of the instruction.
Samples
3 6
2 3
2 1
1 2
1 3
3 1
3 2
11
1 3 2
1 2 3
1 1 3
1 1 2
3 1 3
3 3 2
2 3
1 3 1
3 1 3
4 2
1 3 2
NO
NO
YES
NO
YES
NO
NO
NO
YES
NO
NO
Sample (1) Explanation
The state of the wormholes can be referred to the image below, where the edges represent the existing and undestroyed wormholes:
An image is available here. If not visible, download it from the "Attachments" section.
Sample (2)
See galaxy/galaxy2.in and galaxy/galaxy2.ans in the attachments.
Sample (3)
See galaxy/galaxy3.in and galaxy/galaxy3.ans in the attachments.
Sample (4)
See galaxy/galaxy4.in and galaxy/galaxy4.ans in the attachments.
Data Range
For all test data, it is guaranteed that , , .
| Test Case No. | Special Restriction | |||
|---|---|---|---|---|
| None | ||||
| No operations of type and | ||||
| No operations of type | ||||
| None | ||||