F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Dominoes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 710    Accepted Submission(s): 115


Problem Description
A domino contains two ends, each labeled with number between 1 and 6. You are to write a program that determines if a set of dominoes can be organized in a line so that all dominoes are used; numbers on successive dominoes match; and the numbers on both ends match. You are allowed to rearrange and flip the dominoes arbitrarily. For example, the five dominos: (3 3), (3 1), (4 3), (1 6), and (4 6) can be arranged as:

The five dominos: (4 5), (3 4), (1 2), (2 3), and (5 5) cannot be arranged with all ends matching.
 

Input
The input contains a list of domino-sets. The first line of each set contains a single integer corresponding to the number of dominos in the set ¨C 3 <= N <= 10. The next N lines each contain the two values on a single domino. The end of input is denoted by N = 0.
 

Output
Your program should produce one line of output for every set of dominos. The format should be: ˇ°Set #1: YESˇ± or ˇ°Set #1: NOˇ±.
 

Sample Input
3 1 2 3 2 3 1 5 4 5 3 4 1 2 2 3 5 5 5 3 3 3 1 4 3 1 6 4 6 0
 

Sample Output
Set #1: YES Set #2: NO Set #3: YES
 

Author
2008 ACM ICPC Regional hangzhou
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 19:59:44, Gzip enabled