1 人解决,2 人已尝试。
1 份提交通过,共有 3 份提交。
9.7 EMB 奖励。
单点时限: 5.0 sec
内存限制: 256 MB
The group of travelers has an opportunity to visit several cities. Each traveler states two wishes on what city he/she does want or does not want to visit. One wish expresses will to visit or not to visit exactly one city. It is allowed that both wishes of the one traveler are the same or that they are opposite – i.e. I want to visit city A, and I do not want to visit city A.
Your task is to write a program that:
If there are several possible solutions, your program should output anyone of them.
The first line of the input contains two positive integers $n$ and $m$ ($1 \le n \le 20~000, 1 \le m \le 8~000$); $n$ is the number of travelers, and $m$ is the number of cities. The travelers are numbered from $1$ to $n$, and the cities are numbered from $1$ to $m$. Each of the following $n$ lines contains two nonzero integers, separated by single space. The $i+1$-th line contains numbers $w_i$ and $v_i$ representing wishes of the $i$-th traveler, $-m \le w_i, v_i \le m, w_i,v_i \ne 0$. Positive number means that the traveler wishes to visit that city, and negative number means that the traveler does not wish to visit the city specified by the absolute value of the number.
Your program should write one nonnegative integer $l$, the number of cities to be visited, in the first line of the output. In the second line, there should be written exactly $l$ positive integers in the ascending order, representing cities to be visited.
In case it is not possible to form such a list of cities, your program should write in the first and only line the word NO
.
3 4 1 -2 2 4 3 1
4 1 2 3 4
1 人解决,2 人已尝试。
1 份提交通过,共有 3 份提交。
9.7 EMB 奖励。