Functional Graph

You can think of every connected component of a functional graph as a rooted tree with all edges directed toward the root plus an additional edge going out of the root.

Ideas:

Given a functional graph tell where a vertex will land after following the edge K times. K < 10^12.

Solution : Binary Jumping

Reachablity in Functional Graph

Solution : Graph Coloring https://atcoder.jp/contests/abc357/tasks/abc357_e