deltree
Time limit1sMemory limit128 MB
From a log of cd and dir commands, find the minimum space a final deltree command is guaranteed to free.
- Level
Medium5 of 10
- Topics
- Tree, Simulation
- Solved
- No attempts yet
Problem
You have run out of disk space and decided to delete some of your directories. Before you decide what goes, you look at what your file system holds, and you do that from a command line interface. The interface used in this problem is called MSDOS--, since it is MSDOS with fewer features. The commands of MSDOS-- are as follows.
-
cd <directory>:<directory>is a relative path to a descendant of the current directory. The command moves the current directory to<directory>. For example, when the current directory is\A\B\andC\Dsits below it, runningcd C\Dmakes the current directory\A\B\C\D\. -
cd \: moves the current directory to\, the root of the file system. For example, when the current directory is\A\B\, runningcd \makes the current directory\. -
cd ..: when the current directory is not\, moves the current directory to its parent. For example, when the current directory is\A\B\, runningcd ..makes the current directory\A\. -
cd \<directory>: the same as runningcd \and thencd <directory>. -
dir: lists the names of the files and directories that sit directly in the current directory, one name per line. A name is made of lowercase and uppercase letters, digits, and dots (.). Directory names come before file names, and a directory takes a line by itself. A file name is followed by a single space and its size. A listing produced bydirhas this format.HW1 HW1.old Syllab.pdf 10000 notes.txt 3241 -
deltree <directory>:<directory>is a relative path to a descendant of the current directory. The command deletes<directory>together with every file and subdirectory below it, freeing that much space. For example, when the current directory is\A\B\andC\Dsits below it, runningdeltree C\Ddeletes\A\B\C\D\and everything below it. -
deltree \<directory>: the same as runningcd \and thendeltree <directory>. -
exit: terminates the command line interface.
A scenario is an exploration, a consistent series of cd and dir commands with their results starting from the root, followed by exactly one deltree command. The exploration does not reveal the whole file system. A directory you never opened with dir may be empty. Given a scenario, find the maximum space its deltree command is guaranteed to free. That is the smallest amount deltree deletes over all file systems consistent with the exploration.
Input
The input holds several independent scenarios. One empty line follows each scenario. The input ends with an exit command. Every command in the input is preceded by a > sign with no space in between, and the result lines a command produces carry no >. The length of a file name does not exceed 50. The input is always correct.
Output
Write the result of the th scenario as a single integer on the th line of the output.