Logo
(追記) (追記ここまで)

8093번 - Credibility of Witnesses 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB1110787.500%

문제

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 assume that every witness implicitly states: “I agree with myself”.

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.

Write a program that:

  • reads the number of witness and their testimonies from the standard input,
  • finds all the witnesses that are not credible,
  • writes the result to the standard output.

입력

In the first line of the standard input there is a single integer n, 1 ≤ n ≤ 3,000, which is the number of witnesses. In the second line there is a single integer m, 0 ≤ m ≤ 8,000, 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”.

출력

In the standard output 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).

제한

예제 입력 1

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

예제 출력 1

1
3
4
6

힌트

출처

Olympiad > Polish Olympiad in Informatics > POI 1996/1997 > Stage 3 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /