Folder Cleanup (small)
InterviewTime limit1sMemory limit1024 MB
Given a folder tree with files, answer queries that ask, for each folder, how many distinct file names and how many total files sit under it.
Problem
The main folder contains various files and folders.
main
├─ FolderA
│ ├─ File1
│ └─ File2
└─ FolderB
├─ FolderC
├─ File1
└─ File3
The structure above shows the hierarchy under the main folder. FolderA, FolderB, and FolderC are folders, and File1, File2, and File3 are files. Files with the same name are the same file.
A folder cannot contain two or more files with the same name.
A directory under main cannot contain two or more folders with the same name.
To clean up the folders, you want to inspect the files under the main folder.
Write a program that answers queries about folders and files.
Input
The first line gives the total number of folders and the total number of files under the main folder, separated by a space.
Lines 2 through each give the name of the parent folder , the name of the folder or file , and a value indicating whether it is a folder, separated by spaces.
is 1 if is a folder and 0 if is a file.
Line gives the number of queries .
The next lines each contain a query. Each query gives the path of a folder starting from main. For example, if a query is about FolderB inside the main folder, it is given as main/FolderB, the path of FolderB. The path given in a query is guaranteed to contain an existing folder.
Output
For each query, in order, print on one line the number of distinct file names and the total number of files under that folder.
The number of distinct file names counts identical files as one. The total number of files counts each file separately even if there are identical files.
For example, if there are 5 files named File1, the number of distinct file names is 1 and the total number of files is 5.
Constraints
- and consist only of uppercase and lowercase English letters and digits.