Блог пользователя ScienceGuy

Автор ScienceGuy, история, 7 лет назад, По-английски

Hi, can you please tell me the solution for this problem? http://codeforces.com/gym/101147/problem/E

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You can build graph where edge (i, j) exists if |i - j| = d[i] or |i - j| = d[j].
This graph contains only O(N) vertices and edges.
Now you have problem 'find distances from every vertex to N in undirected unweighted graph'.
It can be solved by bfs from N to all other vertices of graph in O(V + E) = O(N).