Candidate Elimination

시간 제한4초메모리 제한2048 MB

요약
스도쿠 그룹의 각 칸 후보 집합이 주어질 때, 정확히 하나의 네이키드 부분집합으로 제거 가능한 후보를 모두 찾는다.
난이도

어려움10점 중 8점

유형
비트 연산, 조합론, 해시맵, 구현
정답자
아직 제출이 없습니다

문제

James has been learning how to solve sudoku puzzles recently. He had recently learned about a concept called "Naked Pairs". A pair of cells PP is called a Naked Pair when it satisfies the following conditions.

  • The two cells lie in the same group. In sudoku, a group is a set of nn cells that must contain all integers from 11 to nn.
  • Both cells contain a subset of the same set of candidates SS, where ∣S∣=2|S|=2.

Given a naked pair, one can remove the candidates in SS from all other cells in the group, since you know that in a valid sudoku each candidate in SS must appear in one of the two cells.

While learning more about it, James realized that the concept of a "Naked Subset" can generalize the naked pairs. A set of cells QQ with kk cells is called a Naked Subset when it satisfies the following conditions.

  • The kk cells lie in the same group.
  • All cells in QQ contain a subset of the same set of candidates S′S', where ∣S′∣=k|S'|=k.

Given a naked subset, one can remove the candidates in S′S' from all other cells in the group, since you know that in a valid sudoku each candidate in S′S' must appear in one of the kk cells.

James has been whining about how hard it is to find naked subsets in very big sudoku puzzles. Given a group, your job is to find every candidate that can be eliminated using exactly one naked subset.

입력

The first line consists of one integer nn, the size of one group. (1≤n≤1051 \le n \le 10^5)

The following nn lines represent cells that belong to the group. The ii-th line consists of one integer S_iS\_i, followed by S_iS\_i distinct integers. The S_iS\_i integers represent the candidates possible on the ii-th cell.

It is guaranteed that the sum of S_iS\_i is at most 5⋅1055\cdot 10^5.

Additionally, it is guaranteed that there is a valid assignment to all cells in the group. In other words, there exists at least one way to choose one candidate per cell, such that all integers chosen are distinct.

출력

Output nn lines. The ii-th line must consist of the candidates that can be removed from the ii-th cell in increasing order, with the format being same as the input format.

힌트

In the first sample, the cells in the group belong to the box with green digits. The removals are done using the following naked subsets.

  • Cells 1,2,31,2,3 have candidates 2,4,5\\{2,4,5\\}, so you can remove 4,5\\{4,5\\} from cell 44, 5\\{5\\} from cell 55 and 2\\{2\\} from cell 99.
  • Cells 1,2,3,51,2,3,5 have candidates 2,4,5,7\\{2,4,5,7\\}, so you can remove 7\\{7\\} from cells 44 and 99.
  • Cells 1,2,3,4,51,2,3,4,5 have candidates 2,4,5,7,8\\{2,4,5,7,8\\}, so you can remove 8\\{8\\} from cell 99.

The sudoku board corresponding to the sample. Generated using HoDoKu, an open source sudoku solver.

예제1

  1. 예제 1

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