File Fix-it (Large)
InterviewTime limit5sMemory limit512 MB
Count the directories along each wanted path that do not exist yet and report how many mkdir calls they need.
Problem
A Unix computer stores data in directories. There is one root directory, and it can contain several directories with different names. Those directories can contain more directories, and so on.
A directory is identified by its name together with its parent directory, the directory it sits directly inside. This is usually written as a path made of several parts, each preceded by one forward slash ('/'). The last part is the name of the directory, and everything before it gives the path of the parent directory. Consider this path:
/home/gcj/finals
It refers to the directory named "finals" inside the directory described by "/home/gcj", which in turn refers to the directory named "gcj" inside the directory described by "/home". The path "/home" has only one part, so it refers to the directory named "home" in the root directory.
To create a directory you use the mkdir command. You give it a path, and mkdir creates the directory that path describes, but only if the parent directory already exists. For example, creating "/home/gcj/finals" and "/home/gcj/quals" from scratch takes four commands:
mkdir /home
mkdir /home/gcj
mkdir /home/gcj/finals
mkdir /home/gcj/quals
Given every directory that already exists on your computer and a list of directories you want to create, count how many mkdir commands you need to create the ones that are not there yet.
Input
The first line of the input gives the number of test cases, . test cases follow. Each case begins with a line containing two integers and , separated by one space.
The next lines each give the path of one directory that already exists on your computer. This list contains every directory already on your computer except the root directory. The root directory is on every computer, so it is never listed.
The next lines each give the path of one directory that you want to create.
Every path in the input follows the format described above. A path consists of one or more lower-case alphanumeric strings (characters 'a' to 'z' and '0' to '9'), each preceded by a single forward slash. These strings are never empty.
Limits
- No path is longer than 100 characters.
- No path appears twice in the list of directories already on your computer, and no path appears twice in the list of directories you want to create. The same path may appear once in each of the two lists.
- If a directory is listed as already being on your computer, its parent directory is listed too, unless the parent is the root directory.
- The whole input is at most 100,000 bytes.
Output
For each test case, print one line in the form "Case #x: y", where x is the case number starting from 1 and y is the number of mkdir commands you need.