Bureaucracy
Time limit3sMemory limit256 MB
Given a sequence of declare and cancel operations forming a chain, determine which laws remain active where a law is active only if no active law cancels it.
- Level
Medium5 of 10
- Topics
- Simulation, Implementation, Array
- Solved
- No attempts yet
Problem
Long ago, in a distant kingdom, the king decided to keep a record of every law in his realm. From that moment on, whenever a new law was passed, a matching entry was added to the law archive.
Many centuries later, scholars discovered that the kingdom had only two kinds of laws:
- a direct law, which establishes a new rule;
- a canceling law, which cancels one earlier law.
A law is considered active if and only if no active law cancels it.
Write a program that determines which laws are still active.
Input
The first line contains an integer , the number of laws that were passed.
Each of the next lines describes one law, in one of the following two formats:
declare--- a direct law was passed.cancel--- this canceling law cancels law number , which is one of the earlier laws.
Laws are numbered starting from 1, in the order in which they appear.
Output
On the first line, print the number of active laws. On the next line, print the numbers of the active laws in increasing order, separated by single spaces.