#377
Unrated
Directory Traversal
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie the cow is surprisingly computer savvy. On her computer in the barn, she stores all of her precious files in a collection of directories; for example:

bessie/ folder1/ file1 folder2/ file2 folder3/ file3 file4

There is a single "top level" directory, called bessie.

Bessie can navigate to be inside any directory she wants. From a given directory, any file can be referenced by a "relative path". In a relative path, the symbol ".." refers to the parent directory. If Bessie were in folder2, she could refer to the four files as follows:

../file1 file2 ../../folder3/file3 ../../file4

Bessie would like to choose a directory from which the sum of the lengths of the relative paths to all the files is minimized.

입력

The first line contains an integer N (2N100,0002 \leq N \leq 100,000), giving the total number of files and directories. For the purposes of input, each object (file or directory) is assigned a unique integer ID between 1 and NN, where ID 1 refers to the top level directory.

Next, there will be NN lines. Each line starts with the name of a file or directory. The name will have only lower case characters a-z and digits 0-9, and will be at most 16 characters long. Following the name is an integer, mm. If mm is 0, then this entity is a file. If m>0m > 0, then this entity is a directory, and it has a total of mm files or directories inside it. Following mm there will be mm integers giving the IDs of the entities in this directory.

출력

Output the minimal possible total length of all relative paths to files. Note that this value may be too large to fit into a 32-bit integer.

예제 입력 1

8
bessie 3 2 6 8
folder1 2 3 4
file1 0
folder2 1 5
file2 0
folder3 1 7
file3 0
file4 0

예제 출력 1

42
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.