SECRETPATHS
Problem
In the kingdom of Philip II of Macedon, there are cities and secret roads, each connecting a pair of cities bidirectionally. From any city, one can travel to any other city using one or more of these secret roads.
As the kingdom faces attack, Philip is forced to destroy some of the secret roads to hinder the enemy's movement between cities. He assigns this task to his trusted advisor Aristides, brother of Pausanias.
Specifically, Philip can ask Aristides to:
- destroy a specific secret road, or
- answer whether it's possible to travel from one city to another using the remaining secret roads that have not been destroyed yet.
Initially, none of the secret roads have been destroyed.
To ensure that communication between Philip and Aristides cannot be easily intercepted by the enemy, the two actions Philip asks of Aristides are encoded. Please carefully read the description of the input and output of the problem.
Input:
The first line of the input contains three integers separated in pairs by a space: , the number of cities; , the number of actions requested by Philip; and an encoding constant , which can take values or .
Following this are lines, each corresponding to a secret road. Each of these lines contains two integers and , separated by a space, indicating there is initially a secret road directly connecting cities and . Cities are numbered from to .
Next, there are lines, each corresponding to an action requested by Philip. Each of these lines contains a character and two integers and . The character is one of the uppercase Latin letters "" or "", and the integers and denote two cities.
When communication starts between Philip and Aristides, the character "" means that Philip requests the destruction of the road between cities and . Sometimes, Philip might get confused and request the destruction of a road that never existed or has already been destroyed; in such cases, no action should be taken. The character "" means that Philip asks whether it is currently possible to travel from city to city using the remaining roads.
If the encoding constant has a value of , then the interpretation of characters "" and "" is always as described above. However, if has a value of , then the interpretation of characters "" and "" switches each time Aristides positively responds to a question from Philip.
Output:
The output should contain one line for each action requested by Philip that corresponds to a question. The line should contain one word, which will be:
- "yes", if it is possible to travel between the two cities, or
- "no", if it is not possible to travel between the two cities.
Constraints
- και
- και για κάθε ενέργεια, και επιπλέον
- Time Limit: sec.
Memory Limit: MB.
For test cases with a total value of , it will be and all destruction actions will precede the questions.
- For test cases with a total value of , it will be .
- For test cases with a total value of , it will be and .
- For test cases with a total value of , it will be .
- For test cases with a total value of , it will be .
Examples of Input - Output Files:
1st
STDIN (secretpaths.in)
8 7 0
3 5
8 4
1 6
2 8
1 8
8 3
7 3
B 5 3
A 3 8
B 2 7
B 1 4
A 8 1
B 1 4
B 6 3
STDOUT (secretpaths.out)
yes
no
yes
no
no
Explanation of the first example
In the first example, , so the meaning of the characters "" and "" does not change - "" always signifies the destruction of a road and "" always signifies a query.
Therefore, the executed actions are in order:
- Query: Is it possible to travel between cities and ? The answer is yes.
- Destruction of the road between cities and .
- Query: Is it possible to travel between cities and ? The answer is no.
- Query: Is it possible to travel between cities and ? The answer is yes.
- Destruction of the road between cities and .
- Query: Is it possible to travel between cities and ? The answer is now no.
- Query: Is it possible to travel between cities and ? The answer is no.
2nd
STDIN (secretpaths.in)
8 7 1
3 5
8 4
1 6
2 8
1 8
8 3
7 3
B 5 3
A 3 8
A 3 8
A 2 4
B 2 7
B 1 4
A 6 7
STDOUT (secretpaths.out)
yes
yes
no
yes
no
Explanation of the second example
In the second example, , so the meaning of the characters "" and "" is reversed every time a query receives a positive answer. The actions executed are as follows:
- Query: Is it possible to travel between cities and ? The answer is yes. After this answer, the meanings of "" and "" are reversed.
- Query: Is it possible to travel between cities and ? The answer is yes. After this answer, the meanings of "" and "" are reversed again.
- Destruction of the road between cities and .
- Destruction of the road between cities and . This road does not exist, so nothing happens.
- Query: Is it possible to travel between cities and ? The answer is no. After this answer, the meanings of "" and "" are not reversed.
- Query: Is it possible to travel between cities and ? The answer is yes. After this answer, the meanings of "" and "" are reversed.
- Query: Is it possible to travel between cities and ? The answer is no.
Note: The network of cities and roads for both examples that follow is depicted in the following diagram. Only the encoding constant and the requested actions change.
Comments