6B - President's Office I submitted this solution — 69647174

What I am trying to do is to start dfs starting on the first cell of the president's table. If there is another table in that cell's neighbour i call the color function which is also dfs but on the deputy's table and increase the ans (res) by 1.

I do not know what is wrong in this approach. Can anyone help?

UPD: Solved thanks to CodingKnight

No need for dfs here.

SpoilerJust use a set and insert the neighbors of the president office. The answer will be the set size

Ya man i checked the editorial too, I know but I m curious about what is wrong with dfs solution

The following accepted solution is a C++17 version of your Java code with slight updates.

69660777

Thanks a lot man! I found the bug in my code comparing with yours. Thanks a bunch

With pleasure. The following is yet another update to the DFS C++17 code in which a third paremeter is added to the DFS function that defines the branching DFS function called when the next location is valid. The color function is not performed as separate version of the DFS function, but using another call of the same DFS function with different branching function parameter.

69703758

There's no need of dfs but then also I implemented it using graphs in C++ and got it accepted. U can find my submission here. 69730654

You can even simulate the set of distinct characters using a 0/1 array of integers, as the number of deputies is guaranteed to not exceed 25.

69800381