WA in WORDS1

I got “Wrong Answer” in WORDS1 (C99 strict) but I have not idea what is wrong with it.
Can anyone help me finding wrong part of my code or failing test cases?
Here is my solution.

http://www.codechef.com/viewsolution/3787646

Thanks in advance!

I found that my code fails in the following test case:

1
8
ab
ga
bc
cg
fc
cd
ef
de

In thie case, “Ordering is possible” but the original code displays “The doore cannot be opened.”
This happens because the coloring was not complete in the original code.
So I changed to use the following function instead of setting value directly.

 void setColor(int v, int c) {
  int cv = getColor(v);
  if (cv == c) {
    return;
  }
  color[v] = c;
  if (cv != v) {
    color[cv] = c;
  }
}

Now the above test case passes but I got WA again.
Is there any other problem?

Updated version of my solution is here:

http://www.codechef.com/viewsolution/3787714

You have a typo in The door cannot be opned. :wink:

Thanks betlista!!!
I fixed the typo and finally the code has been accepted.
I can sleep well tonight.
Thanks again!