EBAD's blog

By EBAD, history, 6 years ago, In English

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.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
  Vote: I like it -18 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Will this tree concept work for cyclic graph ? (Subtree)

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    The graph isn't a tree.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +20 Vote: I do not like it

    i have some problem in 161D

    your comment help me a lot thx.

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Are negative weights allowed?