In a country (my memory fails to say which), the candidates {1, 2 ... N} are running in the parliamentary election. An opinion poll asks the question "For any two candidates of your own choice, which election result would make you happy?". The accepted answers are shown in the table below, where the candidates i and j are not necessarily different, i.e. it may happen that i=j. There are M poll answers, some of which may be similar or identical. The problem is to decide whether there can be an election outcome1 that conforms to all M answers. We say that such an election outcome is perfect. The result of the problem is 1 if a perfect election outcome does exist and 0 otherwise.
Write a program that reads sets of data from an input text file. Each data set corresponds to an instance of the problem and starts with two integral numbers: 1≤N≤1000 and 1≤M≤1000000. The data set continues with M pairs ±i ±j of signed numbers, 1≤i,j≤N. Each pair encodes a poll answer as follows:
Accepted answers to the poll question Encoding
______________________________________________________________________________________________________
I would be happy if at least one from i and j is elected. +i +j
I would be happy if at least one from i and j is not elected. -i -j
I would be happy if i is elected or j is not elected or both events happen. +i -j
I would be happy if i is not elected or j is elected or both events happen. -i +j