#P9831. [ICPC2020 Shanghai R] Gitignore
[ICPC2020 Shanghai R] Gitignore
题目描述
Your git project (you don't need to be familiar with git to solve this problem) has some files that should be ignored from synchronizing. You need to calculate the minimum number of lines needed for gitignore.
Formally, your project is a folder. A folder can have files and sub folders. There are no empty folders (i.e. folders without any files or sub folders inside). Initially, the git software will synchronize all the files in your project. However, you can specify some files and folders in the settings (which is called gitignore) to exclude them from synchronizing. For each line in gitignore, you can specify either a file or all the files in a folder. You can ignore the whole project folder (i.e. an empty line in gitignore).
You are given paths for all the files in the project and whether they should be ignored or shouldn't. Your task is to calculate the minimum number of lines for gitignore.
输入格式
The input contains several test cases. The first line contains a single positive integer which is the number of test cases. For each test case, you are first given two non-negative numbers and . And then non-empty lines of file paths that should be , and non-empty lines of file paths that should be ignored.
The paths are strings containing lower-cased English alphabets and slashes (/
) only. Slashes are used to separate folders, sub folders and file name. For exapmle, a/b/c/d
indicates folder a
in the project folder, folder b
in folder a
, folder c
in b
and file d
in folder c
. All the paths are valid, specifically:
- The path is non-empty and it always indicates a file (i.e. the path does not end with a slash).
- The path does not start with a slash.
- Folder names and file names are non-empty (i.e. there are no consecutive slashes).
- File paths are always unique (i.e. all the paths in a test case are different).
- In a folder, no sub folders and files share the same names. For example, there won't be two files
a/b/a
anda/b/a/d
in one test case. However, filesa/b/a
anda/b/b
are allowed.
holds and in the whole input there are no more than characters in file paths (i.e. the sum of lengths of file path strings in the whole input file is no more than ).
输出格式
lines of non-negative integers, the minimum number of gitignore lines for each test case.
题目大意
你使用 git 管理的一个项目有一些需要被忽略的文件。你需要计算 .gitignore 文件中至少写入多少行。
详细来说,你的项目是一个文件夹,文件夹可以含有文件或子文件夹。在本题中,不会出现空文件夹(不含文件或子文件夹的文件夹)。git 软件会同步你项目中所有的文件,但是,你可以在 .gitignore 中写入一些信息,使某些文件或文件夹不被同步。在 .gitignore 文件中的一行,你可以指定一个文件或者一个文件夹,使得这个文件或这个文件夹中的所有文件不被同步。你不可以忽略整个项目文件夹。
你会得到项目中所有文件的路径,以及他们是否应该被同步,你的任务是计算 .gitignore 文件中最少的行数。
2
3 0
data/train
data/test
model
3 1
data/train
data/test
model
data/sample
2
3
提示
In the first sample test case, the corresponding gitignore file contains lines: a folder line data/
and a file name model
.
In the second sample test case, the corresponding gitignore file contains file lines: data/train
, data/test
and model
.