Spectrum

No attempts yetTime limit3sMemory limit128 MB

Problem

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.

  1. Targets directly connected to target1 are 0 hops away.
  2. Targets directly connected to a 0 hop target, and not already counted as a 0 hop target or as target1 itself, are 1 hop targets.
  3. In the same way, targets directly connected to an n hop target and not already counted among the 0 through n hop targets are n+1 hop targets.

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.

  • If either target is not in the database yet, add it first, then create the connection.
  • If the two targets are already connected, do nothing. This is not an error. There is at most one direct connection between any two targets.
  • If target1 and target2 are the same string, handle the line as if it read add target1. This is not an error.

connections target1

Reports how many targets sit at each hop count from target1.

  • For each hop count, print the hop count, a colon, a single space, and the number of targets at that hop count with no leading zeroes, on a line of its own. Start at hop count 0 and stop after the last hop count whose number of targets is not zero.
  • If target1 has no connections, print a line containing only no connections.
  • If target1 is not in the database, print a line containing only target does not exist.

associated target1 target2

Reports whether a connection exists between the two targets.

  • If a path exists, print 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.
  • If no path exists, print no on a line of its own.
  • If target1 or target2 is not in the database, print a line containing only target does not exist.
  • A target has no hop count with respect to itself, so when target1 and target2 are the same target, print no.

Input

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.

Output

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.