RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0322 파일 입출력

Directory Traversal

Platinum IV 플래티넘 IV
난이도
2s
시간 제한
256MB
메모리 제한
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.

Problem credits: Mark Gordon

제약

Problem credits: Mark Gordon

입력 형식

The first line contains an integer N (\(2 \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 \(N\), where ID 1
refers to the top level directory.

Next, there will be \(N\) 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, \(m\). If
\(m\) is 0, then this entity is a file. If \(m > 0\), then this entity is a
directory, and it has a total of \(m\) files or directories inside it. Following \(m\)
there will be \(m\) 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.

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 dirtraverse.in
출력을 쓸 파일 dirtraverse.out
예제 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
출력
42
설명

This input describes the example directory structure given above.

The best solution is to be in folder1. From this directory, the relative paths
are:

file1
folder2/file2
../folder3/file3
../file4
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2017-2018 > February > Gold

태그

평가 및 의견

Directory Traversal

개요
출제자 난이도 Platinum IV 플래티넘 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Directory Traversal

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8