#P13044. [GCJ 2021 Finals] Slide Circuits
[GCJ 2021 Finals] Slide Circuits
题目描述
Gooli is a huge company that owns buildings in a hilly area. Five years ago, Gooli built slides that allowed employees to go from one building to another (they are not bidirectional), starting a tradition of building slides between buildings. Currently, slides exist.
Melek is Gooli's Head of Transportation and a problem-solving enthusiast. She was tasked with keeping the slides enjoyable to use. The idea she came up with was disabling some slides such that only circuits remained. A circuit is a set of two or more buildings such that there is exactly one slide enabled from building to building , for each , and exactly one slide enabled from building to building . No other slides from or to any of those buildings should be enabled, to prevent misdirection. A state of the slides is then called fun if each building belongs to exactly one circuit.
Slides in Gooli's campus are numbered with integers between 1 and , inclusive. Melek created a slide controlling console that supports two operations: enable and disable. Both operations receive three parameters , and and perform the operation on each slide such that and is a multiple of . An enable operation is valid only if all affected slides are in a disabled state right before the operation is performed. Similarly, a disable operation is valid only if all affected slides are in an enabled state right before the operation is performed.
The following picture illustrates a possible succession of states and operations. The layout has 3 buildings and 3 slides. Slides are light grey when disabled and dark grey when enabled.
- Initial state. All sides are disabled.
- After enable operation with , , and .
- After enable operation with , , and .
- After disable operation with , and .
- After disable operation with , and .
- After enable operation with , and .
Unfortunately, Sult, Melek's cat, found the console and started performing several valid enable and disable operations. After every console operation performed by Sult, Melek wants to know if the state of the slides can be made fun by enabling exactly one currently disabled slide. Note that Melek does not actually enable this slide.
In the picture above, we can see that after the first, third, and last operations, Melek could enable the only disabled slide and get to a fun state. After the second operation, there are two issues. One issue is that there are no currently disabled slides, so Melek cannot enable any. Additionally, the state is already fun, so even if there were additional disabled slides, enabling anything would result in a not fun state. After the fourth operation, there are two disabled slides, but enabling either would not yield a fun state.
All slides are initially disabled, then Sult performs its operations one at a time. After each of Sult's operations, determine which disabled slide, if any, Melek can enable to put the slides in a fun state.
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case starts with a line containing three integers , , and : the number of buildings, slides, and operations to process, respectively. Then, lines follow. The -th of these lines contains two integers and , indicating that the slide with number goes from building to building . Finally, lines represent the operations. The -th of these lines contains a character and three integers , and , describing the -th operation. describes the type of operation using an uppercase for enable and an uppercase for disable. The operation is to be performed on slides with numbers that are simultaneously a multiple of and between and , inclusive.
输出格式
For each test case, output one line containing Case #x:
, where is the test case number (starting from 1) and is an uppercase if there is no way to turn the state of slides created by the first console operations into a fun state by enabling exactly one disabled slide. Otherwise, should be an integer representing that enabling the -th slide would turn the state created by the first console operations into a fun state.
2
3 3 5
1 2
2 3
3 1
E 1 2 1
E 3 3 1
D 1 3 2
D 1 3 3
E 1 2 2
5 8 10
1 5
5 3
4 1
3 2
2 4
2 5
2 1
1 4
E 1 8 2
D 4 8 2
E 3 5 1
E 1 1 3
E 1 1 1
E 5 8 2
D 1 8 3
D 5 8 4
D 4 5 1
E 3 4 1
Case #1: 3 X 2 X 3
Case #2: 3 X 1 1 X X X 3 X 5
提示
Sample Explanation
Sample Case #1 is the one depicted in the problem statement.
The following picture shows the building and slide layout of Sample Case #2.
The sets of enabled slides after each operation are:
- ,
- ,
- ,
- ,
- ,
- ,
- ,
- ,
- , and
- .
Limits
- , for all .
- , for all .
- , for all .
- $\left(\mathbf{X}_{i}, \mathbf{Y}_{i}\right) \neq\left(\mathbf{X}_{j}, \mathbf{Y}_{j}\right)$, for all .
- is either uppercase or uppercase , for all .
- $1 \leq \mathbf{L}_{j} \leq \mathbf{R}_{j} \leq \mathbf{S}$, for all .
- , for all .
- Each operation is valid.
Test Set 1 (10 Pts, Visible Verdict)
- Time limit: 10 seconds.
- .
- .
- .
- .
Test Set 2 (20 Pts, Hidden Verdict)
- Time limit: 120 seconds.
- .
- .
- .
- .