Compressing Commands

시간 제한2초메모리 제한1024 MB

요약
절대 파일 경로들이 주어질 때 작업 디렉터리를 골라 상대 경로 성분 수의 합을 최소로 만든다.
난이도

보통10점 중 7점

유형
트리, 누적 합, DFS, 그리디
정답자
아직 제출이 없습니다

문제

Unlike your friends, you live in a terminal. You are cool. Your terminal is everything to you: you have optimized the font, colour scheme, keyboard shortcuts, and what not.

Once thing still annoys you though: all these commands you're typing involve so many file paths and are so long! Then it occurs to you: all this time you have been working from the root directory of the file system, but in fact you can change directory to anywhere you like! This should simplify your life a lot!

This way, if your working directory is /a/b, you can refer to the absolute file path /a/b/x using simply x. To go up a level, you can use .., so that you can refer to /a/y/z as ../y/z, and to /some/other/directory as ../../some/other/directory.

You being you, of course you overdo this and will now use relative paths everywhere!

Given the nn absolute file paths in the command you want to run, find the working directory that minimizes the total number of relative path components. For example, a/a/b/c, and ../../a/b both contain 44 path components. Note that you can only change the working directory to a directory and not to a file path. Filenames will never coincide with directory names in the same directory.

In the first sample it is best to set the working directory to /home/jury/compressingcommands, leading to 66 components: secret, solutions, and ../../hackerman/answers.

In the second sample it is best to set the working directory to /a, leading to 1919 path components: b/a/a/b, a/a, ../b, a/b, b/a/a/a, ../c, and b/a/b.

입력

The input consists of:

  • One line with an integer nn (1≤n≤1051\leq n\leq 10^5), the number of absolute file paths.
  • nn lines, each with a string ss, an absolute file path. Each path contains only lowercase English letters (a-z) and slashes ('/'), starts with '/', does not end with '/', and does not contain consecutive slashes ("//").

The total number of characters in the nn strings is at most 10610^6.

출력

Output the minimal number of relative path components that can be achieved by changing to a different working directory.

예제3

  1. 예제 1

    입력
    3
    /home/jury/compressingcommands/secret
    /home/jury/compressingcommands/solutions
    /home/hackerman/answers
    
    예상 출력
    6
    
  2. 예제 2

    입력
    7
    /a/b/a/a/b
    /a/a/a
    /b
    /a/a/b
    /a/b/a/a/a
    /c
    /a/b/a/b
    
    예상 출력
    19
    
  3. 예제 3

    입력
    3
    /x/y/z
    /x/y/z
    /x/y/z
    
    예상 출력
    3