본문 바로가기

problem solving/Problem Solving

Vase collection

http://acm.pku.edu.cn/JudgeOnline/problem?id=1632

Description

Mr Cheng is a collector of old Chinese porcelain, more specifically late 15th century Feng dynasty vases. The art of vase-making at this time followed very strict artistic rules. There was a limited number of accepted styles, each defined by its shape and decoration. More specifically, there were 36 vase shapes and 36 different patterns of decoration ? in all 1296 different styles.
For a collector, the obvious goal is to own a sample of each of the 1296 styles. Mr Cheng however,like so many other collectors, could never afford a complete collection, and instead concentrates on some shapes and some decorations. As symmetry between shape and decoration was one of the main aestheathical paradigms of the Feng dynasty, Mr Cheng wants to have a full collection of all combinations of k shapes and k decorations, for as large a k as possible. However, he has discovered that determining this k for a given collection is not always trivial. This means that his collection might actually be better than he thinks. Can you help him?

Input

On the first line of the input, there is a single positive integer n, telling the number of test scenarios to follow. Each test scenario begins with a line containing a single positive integer m <= 100, the number of vases in the collection. Then follow m lines, one per vase, each with a pair of numbers, si and di, separated by a single space, where si ( 0 < si <= 36 ) indicates the shape of Mr Cheng's i:th vase, and di ( 0 < di <= 36 ) indicates its decoration.

Output

For each test scenario, output one line containing the maximum k, such that there are k shapes and k decorations for which Mr Cheng's collection contains all k*k combined styles.

Source

Northwestern Europe 2003


Solving

챙이 모으는 도자기에는 36개의 모양과 36개의 무늬패턴이 있고 따라서 조합하면 1296개의 스타일이 있다. 챙은 1296개의 도자기를 다 모으고 싶지만 다 모으기가 쉽지않다. 도자기들의 모양과 패턴이 주어졌을 k개의 모양과 패턴의 조합을 모두 모을 수 있는 최대의 k를 구하라

'problem solving > Problem Solving' 카테고리의 다른 글

Tight words  (0) 2008.10.16
Freckles  (0) 2008.10.16
Bridging signals  (0) 2008.10.16
Kadj Squares  (0) 2008.10.16
Party at Hali-Bula  (0) 2008.10.12