Swamp County Consulting won a contract to build a database that records connections between the things they call targets. Your team implements the storage and the commands below.
A target is a string of at most 32 printing characters with no embedded spaces. A connection is a bidirectional relationship between two targets.
The hop count from one target (call it target1) to the other targets follows these rules.
target1 itself never receives a hop count.
There are at most 100,000 targets and at most 500,000 connections.
Commands
The database has three commands: add, associated, and connections. Nothing is ever deleted, because the Agency never forgets and never makes mistakes. A command starts in the first column of a line, and a command and its parameters are separated by whitespace. No input line is longer than 80 columns. An output line carries no leading and no trailing whitespace.
add target1
Adds the target to the database with no connections. If the target is already in the database, do nothing. This is not an error.
add target1 target2
Creates a bidirectional connection between the two targets.
add target1. This is not an error.connections target1
Reports how many targets sit at each hop count from target1.
no connections.target does not exist.associated target1 target2
Reports whether a connection exists between the two targets.
yes: n on a line of its own, where n is the hop count of target2 with respect to target1. One space follows the colon, n has no leading zeroes, and the line has no trailing space.no on a line of its own.target does not exist.no.The input holds several cases. A line reading reset is not a database command. It separates the commands of one case from the commands of the next, so reset every data structure when you read it.
Read until end of file. There is no end of data marker, and the file does not end with a reset line.
Start each case with a line made of Case, one space, the case number, and a colon. Case numbers start at 1. End each case with a line of ten minus signs.