Software Package Manager
시간 제한1초메모리 제한1024 MB
루트가 있는 의존성 트리에서 설치와 제거 질의를 처리하며 각 단계에서 상태가 바뀌는 패키지 수를 출력한다.
문제
You'd like to design a package manager on your own, and thus you'd like to resolve the dependency problem among packages. If package depends on package , then we must install package before package . Likewise, if we'd like to remove package , we also need to remove package . You know the dependency relations among the packages, and you may assume all packages other than package will rely on exactly one package (package does not rely on any other packages). There are no cycles in the dependency relation (like depends on , depends on , …, depends on but depends on ), and of course no package depends on itself.
Now you'd like to know how many packages have their status changed upon installing or uninstalling a given package. Notice installing an installed package or uninstalling an uninstalled package will not change the status of any package.
입력
The first line of the input is an integer representing the number of packages. The packages are numbered beginning with .
The next line has integers separated by a single space, representing the package that package depends on.
The next line contains an integer representing the number of queries. In the following lines, each line contains a query of form install x or uninstall x representing installing or uninstalling package . You need to maintain the status of each package. Initially, all packages are uninstalled. You need to output how many packages will change the status after the step, and then apply the (un)installation.
출력
The output consists of lines. The -th line is an integer representing the number of packages whose status change at step .