We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
C++ solution, passes all test cases without using recursion. Computes the nimber for node x as the smallest non-negative integer not equal to the nimbers of any nodes in x's adjacency list. This can be done non-recursively using DFS with a stack. Once you have the nimbers, just take the cumulative XOR of all the initial positions, and you get the answer.
Play on benders
You are viewing a single comment's thread. Return to all comments →
C++ solution, passes all test cases without using recursion. Computes the nimber for node x as the smallest non-negative integer not equal to the nimbers of any nodes in x's adjacency list. This can be done non-recursively using DFS with a stack. Once you have the nimbers, just take the cumulative XOR of all the initial positions, and you get the answer.