BUREAU - Bureaucracy

no tags 

 

Many centuries later lawyers discovered that there were only two types of laws in the kingdom:
² direct law, that states a new norm;
² canceling law, that cancels one of the previous laws.
The law is considered active if and only if there is no active law that cancels it.
You are to write program that ¯nds out which laws are still active.

Long ago, in a kingdom far, far away the king decided to keep a record of all laws of his kingdom. From that moment whenever a new law was passed, a corresponding record was added to the law archive.

Many centuries later lawyers discovered that there were only two types of laws in the kingdom:

  • direct law, that states a new norm;
  • canceling law, that cancels one of the previous laws.

The law is considered active if and only if there is no active law that cancels it.

You are to write program that finds out which laws are still active.

 

Input

The first line of the input contains T, the number of test cases. T test cases follow.

The first line of each test case contains an integer number n (1 <= n <= 100000) - the number of passed laws.

The following n lines describe one law each. Each description has one of the following formats:

  • "declare", meaning that a direct law was passed.
  • "cancel i", where i is the number of law being cancelled by this one.

The laws are numbered from one.

 

Output

For each test case your output must contain a line with the number of active laws. The following line must contain numbers of these laws listed in increasing order.

 

Example

Input:
1
5
declare
cancel 1
declare
cancel 2
cancel 3

Output:
3
1 4 5

hide comments
[[soup_boy]]: 2011-03-06 01:45:42

Is there a case where a law could cancel itself?

thanks

Last edit: 2011-05-15 15:21:58
Michael T: 2011-02-12 09:13:18

@Fidel: One python AC being 6th in overall ranking doesn't mean anything.

Last edit: 2011-02-12 09:17:41
Fidel Schaposnik: 2011-02-11 21:44:34

I don't know if there's a convention here at SPOJ, but in this case it is quite clear that 100.000 actually means 10^5. In any case, I have edited the problem statement to avoid any further confusion...

Last edit: 2011-02-11 21:45:03
numerix: 2011-02-11 21:44:34

If n is "an integer number", how can it be a decimal point?

Seshadri R: 2011-02-11 21:44:34

"The first line of each test case contains an integer number n (1 <= n <= 100.000)"

The dot (.) following 100; is it a decimal point? I know some European countries use comma and dot interchangeably. Which convention does SPOJ follow? (though most of the times, these symbols can be interpreted correctly from the given context)

Last edit: 2011-02-09 05:27:36
Fidel Schaposnik: 2011-02-11 21:44:34

the repetition of the first line comes from some sort of bug in the editor, but i've now corrected it :-) i also increased the time limit slightly, considering that no Java solutions have been accepted. however, seeing that there's already one AC in python my guess is that java should have no problems if optimized a bit...

Efim: 2011-02-11 21:44:34

Please, increase time limit. It is too strict for Java.

:D: 2011-02-11 21:44:34

first you declare the law 1. Then you cancel it with law 2. Next law 3. Then you cancel law 2, so now law 1 stays. Finally law 5 is passed and it negates law 3. So out of laws 1-5, 2 & 3 are removed.

germinating: 2011-02-11 21:44:34

can some one plz explain the sample input ...??

sooshia: 2011-02-11 21:44:34

wow.. i guess this one has LARGE input data. tried python even c++ using cin only to fail by TLE.
gotta use scanf instead.

Edit by LeppyR64: cin/cout are rarely good to use around SPOJ, they're incredibly slow.

Last edit: 2011-01-20 12:53:00

Added by:Fidel Schaposnik
Date:2011-01-19
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACM ICPC 2009, NEERC, Northern Subregional Contest