Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Is the Partition the Graph checker correct?

$
0
0

I didn't want to ask during the contest, but I felt like my solution was correct, yet still got WA. I haven't seen an editorial for the problem yet so I have no way to verify my solution.

So I'd like to ask for a test case that my method fails.

My Approach I picked a root node in the tree (Usually 1, but I tried others) and calculated the distance to each node from there, using Breath First Search/Dijkstra.

I then grouped the nodes into 4 groups with each node going into the group number dist_from_root%4

If group(0) + group(2) == group(1) + group(3), Then the answer is 1 and the sets are chosen in the same way

If they not equal I moved only nodes from one of the groups across to the other side until they were equal, but making the answer 2.

Solution Codehttps://www.codechef.com/viewsolution/22349636

Please help me find a failed test case, I've tried to find my error but could not.


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>