#P8819. [CSP-S 2022] 星战
[CSP-S 2022] 星战
Description
In this round of interstellar war, we have established bases in the universe, connected by directed wormholes. We group all wormholes whose destination is base as base ’s wormholes.
Amid fierce warfare, these wormholes are unlikely to last long, and enemy strikes may come at any time. The effective strikes can be divided into two types:
- The enemy destroys a wormhole. This makes it impossible to directly travel between its two connected bases via this wormhole, but such a strike cannot destroy the two bases it connects.
- The enemy destroys a base. Since the key technology of a wormhole is concentrated at its exit, this causes all wormholes of that base that have not yet been destroyed to be destroyed together. Wormholes departing from this base, however, will not be destroyed.
Note: Destruction only makes wormholes unusable and does not erase their existence.
To resist the enemy and maintain links between units and bases, we developed two special forces to repair wormholes:
- Type A special forces can repair a specific wormhole.
- Type B special forces can repair all damaged wormholes of a single base.
Given the nature of enemy strikes, we do not stockpile too many strategic supplies at bases. Therefore, as long as any one wormhole of a base is repaired and usable, that base is considered usable.
We have mastered a stringent spatial property that allows our warships to instantaneously jump along wormholes into enemy territory for precise strikes.
To seize the best timing for a counteroffensive, the command must track all changes on the battlefield. The commander believes:
- If, starting from any of our bases, by choosing an appropriate route, one can shuttle through wormholes infinitely many times (the same base or wormhole may be visited multiple times), then this base can “launch a counterattack”.
- To keep the shuttling process continuous and minimize mass–energy loss when switching wormholes at a base, a base can achieve “continuous traversal” if and only if exactly one wormhole departing from that base is usable.
- If all our bases can both “launch a counterattack” and achieve “continuous traversal”, then this moment is an excellent “counteroffensive” moment.
You are ordered to promptly report, based on real-time battlefield information, whether a “counteroffensive” can be carried out at the current moment.
Input Format
The first line contains two positive integers .
The next lines each contain two integers , representing a directed wormhole from base to base . It is guaranteed that , and there are no duplicate wormholes. Initially, all wormholes and bases are intact.
The next line contains a positive integer denoting the number of queries.
The following lines each describe a query or operation. First read an integer indicating the instruction type:
- If , the next two integers indicate the enemy destroyed the wormhole from base to base . It is guaranteed that this wormhole exists and has not been destroyed.
- If , the next integer indicates the enemy destroyed base . If all wormholes of this base have already been destroyed, then this strike has no effect.
- If , the next two integers indicate we repaired the wormhole from base to base . It is guaranteed that this wormhole exists and has been destroyed.
- If , the next integer indicates we repaired base . If this base has no destroyed wormholes, then this repair has no effect.
After each instruction is executed, determine whether a counteroffensive can be carried out. Output YES if it can, otherwise output NO.
Output Format
Output exactly lines. For each instruction, output whether a counteroffensive can be carried out after the instruction is executed.
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
Hint
【Sample Explanation #1】
You can refer to the following image for the wormhole status. In the figure, an edge denotes a wormhole that exists and has not been destroyed:

【Sample #2】
See galaxy/galaxy2.in and galaxy/galaxy2.ans in the attachment.
【Sample #3】
See galaxy/galaxy3.in and galaxy/galaxy3.ans in the attachment.
【Sample #4】
See galaxy/galaxy4.in and galaxy/galaxy4.ans in the attachment.
Constraints
For all testdata, it is guaranteed that , , .
| Test point | Special constraints | |||
|---|---|---|---|---|
| None | ||||
| It is guaranteed that there are no cases with or . | ||||
| It is guaranteed that there are no cases with . | ||||
| None | ||||
Translated by ChatGPT 5
京公网安备 11011102002149号