Polish version    English version  
  History of OI -> IV OI 1996/1997 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
IV Olimpiada Informatyczna 1996/1997

Task: WIA
Author: Grzegorz Jakacki
Credibility of witnesses

III stage contest  
Source fileWIA.??? (e.g. PAS,C, CPP)
Executable fileWIA.EXE
Input fileWIA.IN
Output fileWIA.OUT

Witnesses, numbered from 1 to n, have made their testimonies in a court. Each testimony is a statement of the form: "the i-th witness agrees with the j-th witness" or "the i-th witness does not agree with the j-th witness".

If the i-th witness agrees with the j-th witness then he agrees also with all the witnesses that the j-th witness agrees with. Similarly, the i-th witness does not agree with all the witnesses that the j-th witness does not agree with.

We say that witness A is not credible if from testimonies made in a court it follows that there exists a witness B such that A agrees with B and A does not agree with B.

Task

Write a program that:
  • reads the number of witness and their testimonies from the input file WIA.IN,
  • finds all the witnesses that are not credible,
  • writes the result to the text file WIA.OUT.

Input

In the first line of the text file WIA.IN there is a single integer n, 1 <= n <= 3000, which is the number of witnesses.

In the second line of the text file WIA.IN there is a single integer m, 0 <= m <= 8000, which is the number of testimonies.

In each of the following m lines there are two integers i, j (1 <= i <= n, 1 <= | j | <= n), separated by a single space. If j is positive it describes a testimony: "the i-th witness agrees with the j-th witness". If j is negative it means: "the i-th witness does not agree with the (-j)-th witness".

Output

In the text file WIA.OUT there should be written:
  • a single word NIKT (which means NOBODY in Polish), if it follows from testimonies that there is no witness that is not credible,
  • or - in increasing order - the numbers of witnesses that are not credible (one member in one line).

Example

For the text file WIE.IN
6
12
1 3
1 6
2 -1
3 4
4 1
4 -2
4 5
5 -1
5 -3
5 2
6 5
6 4
the correct answer is the text file WIA.OUT:
1
3
4
6





Print friendly version