아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Sightseeing Tour

시간 제한2초메모리 제한512 MB

요약
각 친구는 도시를 방문하거나 피하려는 소원을 가지며, 모든 친구가 최대 한 번만 실망하도록 방문할 도시를 정하거나 불가능하면 -1을 출력한다.
난이도

보통10점 중 6점

유형
그래프, DFS, 구현
정답자
아직 제출이 없습니다

문제

A group of nn friends has decided to take a tour. They can visit some of mm 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: nn, mm and kk --- the number of friends, the number of cities and the total number of wishes (1≤n,m,k≤100,0001 \leq n, m, k \leq 100\\,000).

Each of the following kk lines contains two integers aa and bb and describes a wish (1≤a≤n,1≤∣b∣≤m1 \leq a \leq n, 1 \leq |b| \leq m). If b>0b > 0, the person aa wants to visit the city bb. If b<0b < 0, the person aa wants to avoid visiting the city −b-b. 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 −1-1.

In the other case the first line of output must contain a single integer kk --- the number of cities to visit by the group.

The second line must contain kk 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 kk, you can output any correct answer.

예제2

  1. 예제 1

    입력
    3 5 6
    1 2
    1 3
    1 -4
    2 3
    2 4
    2 5
    
    예상 출력
    3
    2 3 5
    
  2. 예제 2

    입력
    3 3 6
    1 -1
    1 2
    2 -2
    2 3
    3 -3
    3 1
    
    예상 출력
    0