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

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

Swish

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

요약
링과 점의 위치가 정해진 카드 최대 20장을 모두 유효한 순환 스위시로 나누고, 그 개수의 최솟값을 구한다.
난이도

보통10점 중 7점

유형
그래프, 백트래킹, 비트 연산, 조합론
정답자
아직 제출이 없습니다

문제

Swish (TM) is published by ThinkFun.com

You and your friends are playing a card game called "Swish."  In Swish, each player tries to collect as many cards as possible from the table by collecting them in groups called "swishes."  Almost all the cards from the table have been collected so far, and so you wonder if there is a way to group the remaining cards into swishes so that there are no cards left over.

Each card has exactly 11 dot and 11 ring on it.  The cards are transparent and rectangular, so you can place them on top of each other and see the rings and dots on the cards underneath.  A ring can enclose a dot if they share the same position.  Each dot/ring pair can be in one of exactly 1212 positions on the card, which are numbered as shown in the Figure below:

Figure 1: Possible positions for rings and dots on each card.

A swish is formed by choosing an arbitrary card to be the start of a pile, then adding more cards to the pile so that a new card has a ring which encloses the previous card's dot, and so that the dot of the added card does not overlap any ring/circle pairs already placed.  Cards can be flipped and/or rotated in any way when they are being added to a swish, but the cards must lay exactly on top of each other and must maintain a "portrait" orientation (being higher than it is wide).  The last card chosen must have a dot which is enclosed by the first card's ring. By forming swishes in this way, a valid swish cannot contain a smaller swish if all the card orientations are kept the same.  A valid "swish" can contain anywhere from 22 to 1212 cards.

Is it possible to group all the cards from the table into swishes, and if so, what is the minimum number of swishes necessary to do so?

입력

The input consists of a single test case. The first line of input contains a single integer nn, where 1≤n≤201 \leq n \leq 20 is the number of cards on the table. The next nn lines will describe each card.  Each line will contain two integers rr and dd, where 0≤r,d≤11,r≠d0 \leq r, d \leq 11, r \ne d are the positions of the ring and dot on that card, respectively.

The positions of the rings and the dots are given in row order, as shown in Figure 1.  The positions are symmetric, so that a ring or a dot that is on position 00 may be rotated and/or flipped so that the position changes to 2,9,2, 9, or 1111.  Similarly, a ring or dot on position 44 may be flipped and/or rotated so that the position changes to 77.  The other positions may also be changed by rotating and/or flipping the card.

출력

If it is not possible to arrange the cards in swishes so that each card is a part of exactly one swish, then output -1.  Otherwise, output an integer denoting the minimum number of swishes so that each card is a part of exactly 11 swish.

예제3

  1. 예제 1

    입력
    4
    9 4
    9 1
    4 9
    1 9
    
    예상 출력
    1
    
  2. 예제 2

    입력
    5
    3 6
    7 2
    11 0
    9 4
    0 6
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    12
    6 5
    4 0
    7 11
    5 8
    1 6
    10 4
    11 9
    8 9
    2 8
    3 4
    0 1
    2 10
    
    예상 출력
    1