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

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

Given a weighted graph with n nodes and m edges. for each node v we should calculate number of nodes u such that d(v,u)<=k . n,m<=5e4 k<=100; Please somebody help me. UPD: I don't know if it's important or not but Wi<=100 for every edge.

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

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

As k is small here. You can do DP with states — DP(u, k) =  number of nodes in subtree of u at distance k. Then you need to combine answers for subtrees. Complexity O(nk). (Notice that we are not interested in any path of length  > k)

However this problem can also be solved in O(nlogn), for large k, using Centroid Decomposition.
You can submit the unweighted graph version of this problem here — 161D - Distance in Tree.

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

Are negative weights allowed?