J - Jack's socks
08.01.2010
![]() ![]() ![]() Time limit: 11 s Jack is a scientist. As you probably realize, this means he does not pay much attention to what he wears daily. He is also a man, which means that he knows the names of no more than six colors, cannot tell the difference between ecru and white and associates plum only with fruits. But today he is leaving for a conference. He has just pulled a set of single socks out of washing machine and must pair them. He can say which sock is similar to which one, and he may pair only these socks which seem similar. However, many socks are similar to many others. Worse than that, similarity relation is not necessarily transitive. For example, for Jack blue feels similar to seagreen and seagreen to green, but Jack can distinguish between blue and green and say that they are not similar. Jack wonders if there is exactly one way to pair all his socks. Help him by writing an appropriate program. Do not worry: he might be a scientist, but he is not going to wear his socks with sandals. Multiple Test Cases
The input contains several test cases. The first line of the input contains a positive integer Single Instance Input
The first line of input instance contains two integers Single Instance Output
For each input instance your program should check whether there exists exactly one way of pairing all these socks.
If not, it should output a line containing NO. Otherwise, it should output YES in the first line, followed
by ExampleInput2 4 4 1 2 2 3 3 4 4 1 4 3 1 2 2 3 3 4 OutputNO YES 1 2 3 4 Nie możesz wysyłać i oglądać rowiązań tego zadania ponieważ nie jesteś zalogowany. Zaloguj się lub załóż konto. |
Copyright © 2008-2010 Wrocławski Portal Informatyczny
design: rafalpolito.com