I have the following task that I need to solve, but I'm not sure on how to take the conditions into consideration when stating the maximum number of nodes and edges. The problem is as follows:

What I'm thinking is that I first make an empty array and afterwards use Breadth First Search on G, where each visited node is added to the array. In the end the array is counted to find the maximum number of nodes.
Else I would say the maximum number of nodes in the worst case would be nn and then the number of edges would be m3, which in asymptotic notation would result in O(k^2). But, I'm not quite sure in this case either, as Mario cannot move around in the kk grid, as there needs to be some bricks to move on - why I don't think the 'worst case' would be nn.