Sightseeing Tour
시간 제한2초메모리 제한512 MB
각 친구는 도시를 방문하거나 피하려는 소원을 가지며, 모든 친구가 최대 한 번만 실망하도록 방문할 도시를 정하거나 불가능하면 -1을 출력한다.
문제
A group of friends has decided to take a tour. They can visit some of cities during the tour.
The tour guide asked each person to tell her his wishes about visiting cities. Each person can claim for some cities that he wants to visit them, and for some other cities that he wants to avoid visiting them.
The group always travels together. If the group visits some city, all people who claimed that they want to avoid visiting that city get upset. If the group doesn't visit some city, all people who claimed that they want to visit that city get upset.
The guide understands that sometimes it is not possible to satisfy all wishes. She wants to make a plan which cities to visit, so that each person gets upset at most once.
Help the guide to choose which cities to visits to satisfy all wishes, except at most one for each person, or find out that it is impossible.
입력
The first line of input contains three integers: , and --- the number of friends, the number of cities and the total number of wishes ().
Each of the following lines contains two integers and and describes a wish (). If , the person wants to visit the city . If , the person wants to avoid visiting the city . No wish is listed more than once, no person simultaneously wants to visit some city and to avoid visiting it.
출력
If there is no solution, output .
In the other case the first line of output must contain a single integer --- the number of cities to visit by the group.
The second line must contain integers --- the numbers of the cities to visit. They can be listed in any order.
If there are several possible correct answers, any of them can be printed. Note that you need not neither maximize nor minimize , you can output any correct answer.