|
|||||||||||||||||||
|
SPOJ time: 2012-05-26 14:01:59 |
Edge SearchingProblem code: HS09ESN
Poisonous gas has spread through a tunnel complex modeled by graph G. You have been put in charge of a team of mobile agents whose goal is to clean the contaminated complex. Initially, the entire graph G is contaminated. The gas cannot spread past your agents and you can clean an edge, by moving an agent along it. However, if at any point of the process there is an unprotected path (without any agents) containing both clean and contaminated edges, then the former become recontaminated. This is strictly forbidden and should it happen, your mission will fail. The action of only one agent can be performed at a time. The following actions are available:
A contaminated edge e={u,v} becomes clean if either:
Your goal is to clean G using as few agents as possible. InputAt the beginning of the input there is a single positive integer i. After that, i test cases follow. Each test consists of a graph G that is to be searched. The first line of each case is a single positive integer n. Graph G has n vertices. Than all subsequent lines contain a pair of integers u v. Each such line means that an edge u v exists in G. The list of edges ends with a line in which u=0 and v=0. All graphs G are connected, undirected and simple (there are no loops or parallel edges). The majority of tested graphs have less than 5000 vertices, but that is not true for all of them. OutputThe output of each test case should consist of series of agent moves, describing search strategy. Each line should start with a single character from the set {a, r, m, d}, which correspond to: adding an agent, removing an agent, moving an agent, and claiming that the task has been completed, respectively.
If any of the moves leads to recontamination a Wrong answer message will be issued. Note, that moving an agent among e is also considered a recontamination, if the move does not clean e. ScoringYour goal is to minimize the number of agents used during the cleaning process, that is the maximal total number of agents present on G at any point of the cleaning process. If an agent is removed from graph and than added to it again, the total number of agents does not increase. The number of points given in the ranking is scaled so that it is equal to 10 for the contestant whose solution has the smallest score, and is proportionally less for all solutions with larger scores. ExampleInput 2 TipsAny graph may be cleaned by placing n+1 agents, one on each vertex of G, and than using the n+1-th agent to clean all the edges (see the second example). There are four classes of test cases:
Please note
|
||||||||||||||||||
| |||||||||||||||||||