Hedgehog Graph 2
Time limit2.5sMemory limit1024 MB
Given up to 10 functional graphs shaped like a cycle with trees of depth 1, find each cycle length using at most 900 queries that jump x steps from a chosen vertex.
- Level
Hard8 of 10
- Topics
- Implementation, Math, Number theory
- Solved
- No attempts yet
Problem
This is an interactive problem.
Isn't a hedgehog cute?

A cute hedgehog!
Kipa also has the "sea urchin graph," but it makes no sense for there to be no graph matching such a cute hedgehog. So Kipa decided to make the hedgehog graph.
A hedgehog graph is an undirected connected graph that satisfies the following two properties. It has no self-loops (an edge connecting a vertex to itself) and no multiedges (distinct edges and connecting the same two distinct vertices and ).
- There is exactly one cycle. This cycle is called the body of the hedgehog. The size of the body is the number of vertices on the cycle. A cycle always exists, so the body size is always at least .
- Every vertex not on the cycle has degree .
Kipa raised many hedgehog graphs, and now has hedgehog graphs, each with vertices. Kipa decided to pet each hedgehog graph in the following way.
- Orient every edge so that each vertex has exactly one outgoing edge. It can be proven that such an orientation always exists for any hedgehog graph. Kipa has already chosen the orientations arbitrarily, so this step is done.
- Repeat the following up to times.
- Choose a vertex and a positive integer at most .
- Starting from , follow the arrows times to pet the hedgehog graph. Since every vertex has exactly one outgoing edge, the endpoint is uniquely determined, and you can find out which vertex it is.
Kipa wants to know the body size of each hedgehog graph, not just pet them. Kipa finds this too hard to figure out, so the second step is left to you.
You must find the body size of each hedgehog graph from the information you get after running step 2 on it.
Input
The first line contains a positive integer at most . The interaction starts after that.