Describe
According to the Constitution, the Public Peace Commission of the Byteland Democratic Republic should be established through legislative procedures in Parliament. Unfortunately, this has been prevented by the disharmony between the representatives of certain parties.
The Committee must meet the following conditions:
Each party has 1 representatives in the Committee,
If 2 representatives hated each other, they could not all belong to the Committee.
Each party has 2 representatives in the Parliament. The delegates are numbered from 1 to 2n. The representatives numbered 2i-1 and 2i belonged to the first party.
Task
Write a program:
Read from a text file into the number of parties and the unfriendly representatives of the relationship to,
Calculation of the possibility of establishing a peacebuilding Commission, and, if so, a list of members of the Committee,
The result is written to a text file.
Input
In the first line of a text file there are 2 nonnegative integers n and M. Their respective representations: the number of parties n,1 < =n < = 8000 and unfriendly representatives to m,0 <=m <=20000. Each behavior of the M line below is a pair of integers a,b,1<=a
Output
If the committee cannot be created, the text file should include the word NIE. If this is possible, the text file spo.out should include N of integers from the range 1 to 2n, in ascending order, one per line, these numbers are the number represented in the Committee. If the committee can be formed in a variety of ways, the program can write only one of them.
Analysis
- A map of the 2-sat problem
- Just started to write not noticed that the map should be U->v ', v->u ' Can not U '->v, V '->u. Because the former means that if you choose to choose Only V ', the latter if you choose the U ', then choose not to choose V is not related. So the restrictions are wrong.
Cogs-313-Peace Commission-poi2001-2-sat