Анонсирован VK Cup 2018! Регистрация уже идет! Приглашаем ознакомиться с информацией о Чемпионате на его странице. ×

Автор 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.

 » 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(n log n), for large k, using Centroid Decomposition.You can submit the unweighted graph version of this problem here — 161D - Distance in Tree.
•  » » 6 недель назад, # ^ |   +1 Will this tree concept work for cyclic graph ? (Subtree)
•  » » 6 недель назад, # ^ |   +4 The graph isn't a tree.
 » 6 недель назад, # |   0 Auto comment: topic has been updated by EBAD (previous revision, new revision, compare).
 » 6 недель назад, # |   0 Are negative weights allowed?