#PT0213. 软件包管理器 (Package Manager)
软件包管理器 (Package Manager)
Description
Linux users and OSX users must be familiar with package managers. Through the package manager, you can install a certain software package with one line of command, and then the package manager will help you download the software package from the software source, and automatically resolve all dependencies (that is, download and install other software packages that this software package depends on), complete all configurations. apt-get
is used by Debian/Ubuntu, yum
is used by Fedora/CentOS, and Homebrew
is available for OSX.
You decide to design your own package manager. Obviously, you have to solve the dependency problem between packages. If the software package depends on the software package , you must install the software package before installing the software package . At the same time, if you want to uninstall the software package , you must uninstall the software package . Now you have obtained all the dependencies between the packages. Moreover, due to your previous work, in addition to package , the packages in your manager will depend on one and only one package, and package does not depend on any package. There is no ring of dependencies (if there are () packages , where depends on , depends on , depends on , , depends on and depends on , then it is said these packages form a ring) and no package depends on itself.
Now you have to write a dependency resolution program for your package manager. According to the user's actions, when installing and uninstalling a certain software package, users want to quickly know how many software packages' installation status will actually be changed by this operation (that is, how many uninstalled software packages will be installed by the installation operation, or the uninstall operation will uninstall how many installed packages), your task is to achieve this part. Note that installing an installed software package or uninstalling an uninstalled software package will not change the installation status of any software package, that is, in this case, the number of packages that have changed the installation status is .
Input Format
The st line of the input file contains positive integers , representing the total number of packages. The software packages are numbered starting from .
The following line contains integers, separated by a single space between adjacent integers, representing software, the number of the software package that this software package depends on.
The next line contains a positive integer , which represents the total number of queries. Then lines follow, one query per line. There are two types of queries:
install x
: indicates the installation package
uninstall x
: means to uninstall the software package
You need to maintain the installation status of each package. At the beginning, all packages are in an uninstalled state. For each operation, you need to output how many software packages' installation state will change, and then apply this operation (that is, change the installation states you maintain).
Output Format
Output lines. Line of the output file outputs an integer, which is the number of packages whose installation status was changed in step .
7
0 0 0 1 1 5
5
install 5
install 6
uninstall 1
install 4
uninstall 0
3
1
3
2
3
Constraints
For all data, .