#include #include #include constexpr int64_t p = 1000000007; int main() { int n; std::cin >> n; std::vector children(n); std::vector > parents(n); for(int i=0; i> c; children[i] = c-1; parents[c-1].push_back(i); } std::vector dp(n); std::vector visited(n); std::vector refcount(n); std::deque toprocess; for(int i=0; i