CAGES - Lights, Snakes and Cages
In the zoo there are N cages in which we keep N snakes: each snake in its cage. For experimental reasons, in a month we will move each snake to a different cage: this reordering is given in the input.
Each cage is illuminated by special light, which may be of type A, type B or type C. Your task is to assign the lights A, B, C to the cages so that:
1) each snake will change its lighting, i.e. it will be moved to the cage illuminated differently from the cage it currently inhabits;
2) lightings are equally distributed, i.e. the number of cages A, the number of cages B and the number of cages C differ by at most one.
The first line contains an integer N (2 ≤ N ≤ 300 000), the number of snakes and cages. Cages are numbered from 1 to N.
Each of the next N lines contains an integer. When K-th of these lines contains the number L, it means that the snake from the cage K will be moved to the cage L (K ≠ L). Two snakes will not move to the same cage.
Print the string composed of the characters A, B and C, such that the K-th character denotes the lighting of the cage K.
If there are multiple solutions, print any.
@psetter: could you please tell me where am I getting wrong? I keep failing after test case 15 though I believe I've considered all the situations :(
Oh my pretty code but got TLE
@psetter please check my code having id :- 21512185..i am getting wrong answer after 15 test cases
Can anyone tell me where I am going wrong? Submission id : 19827082 .. I used a simple dfs
Last edit: 2016-10-13 22:57:40
the reason this problem cant be solved is snakes,
@psetter Kindly have a look at my solution ( id : 17732677 ), I have considered even the cyclic cases, but still I am getting WA after 15 test cases.
@psetter please check my submission : 17234107!
@author can you please check my submission: 16964085, getting wrong answer after 15 test cases.
Cant find test cases... getting WA...HELP!!!!