Credibility of Witnesses
Time limit1sMemory limit128 MB
Given agree/disagree statements between witnesses, find all witnesses whose implied relations force them to both agree and disagree with some other witness.
- Level
Hard8 of 10
- Topics
- Graph, Union-find, Topological sort
- Solved
- No attempts yet
Problem
There are witnesses, numbered from to , testifying in court. Each testimony has one of two forms:
- witness agrees with witness , or
- witness does not agree with witness .
Agreement carries over other witnesses' opinions. Specifically, if witness agrees with witness , then:
- witness agrees with every witness that witness agrees with, and
- witness does not agree with every witness that witness does not agree with.
Every witness always agrees with themselves.
Witness is not credible if the testimonies together imply that there is some witness for whom witness both agrees with and does not agree with .
Given all testimonies, find every witness who is not credible.
Input
The first line contains an integer (), the number of witnesses. The second line contains an integer (), the number of testimonies.
Each of the next lines contains two integers and (, ). If is positive, the line means "witness agrees with witness ". If is negative, it means "witness does not agree with witness ".
Output
Print one of the following:
- the single word
NIKT(which means "nobody"), if no witness is not credible, or - the numbers of all witnesses who are not credible, in increasing order, one per line.