SPOJ 1436: Is it a tree