Thread: Contest:Collective guarantee

  1. #1
    Registered User slavi's Avatar
    Join Date
    Jan 2003
    Posts
    1

    Contest:Collective guarantee

    Contest:Collective guarantee
    requirements:
    Time Limit: 1 second
    Memory Limit: 1000K
    Language: C
    Closing date:26 January 2003
    send the solutions(source) to [email protected]
    Only source in .c is accepted and files under 1 MB
    if you've got a description of your algorithm you'll get extra points
    There are going to be 2 more problems!

    Somebody of N boys and girls broke mummy's favourite cup. Mummy became angry and numbered the children with positive integers from 1 to N. Then she approached the child number 1 and asked: "Who has broken the cup?" "Me," - he (or she) answered and was punished.

    You, of course, understand that the story is idealized. Practically (we don't know if it was true or not) the boy or the girl number 1 said: "It wasn't me! It was the child number K1!" Then mummy approached number 2 and asked him (or her) the same question...

    Some children tried to answer the truth. Others replied in order to say something. But some children had agreed not to give away a juvenile to mummy: each one of them pointed someone else from the group - in a circle. As a result - mummy was racked. She was despaired to remember what every child had told her about the cup and she wrote down all thier "evidences" on a sheet of paper. Now she's willing to investigate the cause. First of all she decided to find out if there is a "collective guarantee" between some of the children so that it was described above. You are to write a program that would help mummy in such a case - to all appearences it was not the first and not the lsat cup.

    Input
    The first lines contains a positive integer T (0 < T < 1001) - the number of input tests. Each test consists of two lines: the first one contains a number N (0 < N < 25001) - and amount of children. The second line contains N numbers separated with a space - that are the evidences of the children. Mummy has written down at ith position of the line the number of a child that the ith child pointed to, or 0 if the ith child suddenly confessed.

    Output
    You should write one line for each test. It should contain "YES", if the exidences of the children at least seem to be noncontradictory: exactly one child has confessed the he (or she) had broken the cup, and there is no group of children that point to each other in a circle. Otherwise you are to output "NO".

    Sample Input
    4
    4
    2 0 2 2
    4
    2 0 2 1
    5
    2 3 4 1 3
    3
    0 3 2
    Sample Output
    YES
    YES
    NO
    NO

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    I swear, people get more creative by the day to try and get people to do their homework for them Just kidding...the only thing that particularly interested me about the "contest" (still a bit wary ) were the memory and time limitations, anyhow...

    Oh well.

    I believe we have a contest forum here somewhere, though...dig around a bit...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to guarantee alignment with malloc and or new?
    By mynickmynick in forum C++ Programming
    Replies: 16
    Last Post: 08-27-2008, 02:49 AM
  2. Exception-Safe Copy Assignment
    By George2 in forum C++ Programming
    Replies: 22
    Last Post: 04-02-2008, 05:43 AM
  3. string reference
    By matott in forum C++ Programming
    Replies: 30
    Last Post: 08-20-2007, 05:33 PM
  4. Replies: 13
    Last Post: 12-21-2006, 05:28 PM