It is quite strange that the case 5 0,-1,-1,-1,-1,-1 will give 0 while actual answer is -1..i don't think there was any constraint disallowing all negative costs or 0 connections ans still the code is AC in practice.here is the code link.
here is the link for codechef AC code
http://www.codechef.com/viewsolution/2384166
@jay_adm we want you to look into the matter and make required changes .