This is an unusual problem in an unusual contest, here is the announcement: http://cf.m27.workers.dev/blog/entry/73543
You are given a directed acyclic graph \(G\) with \(n\) vertices and \(m\) edges. Denote by \(R(v)\) the set of all vertices \(u\) reachable from \(v\) by moving along the edges of \(G\). Find \(\sum\limits_{v=1}^n |R(v)|^2\).
Output
Print one integer — the answer to the problem.
Примеры
| № | Входные данные | Выходные данные |
|
1
|
5 4 1 2 2 3 3 4 4 5
|
55
|
|
2
|
12 6 1 2 3 4 5 6 8 7 10 9 12 11
|
30
|
|
3
|
7 6 1 2 1 3 2 4 2 5 3 6 3 7
|
45
|