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.

# | User | Rating |
---|---|---|

1 | tourist | 3496 |

2 | Um_nik | 3337 |

3 | Petr | 3298 |

4 | W4yneb0t | 3218 |

5 | Radewoosh | 3216 |

6 | OO0OOO00O0OOO0O0…O | 3188 |

7 | Syloviaely | 3168 |

8 | izrak | 3109 |

9 | anta | 3106 |

10 | fateice | 3099 |

# | User | Contrib. |
---|---|---|

1 | tourist | 184 |

2 | rng_58 | 170 |

3 | csacademy | 165 |

4 | Petr | 158 |

5 | Swistakk | 154 |

6 | lewin | 149 |

7 | Errichto | 147 |

8 | matthew99 | 146 |

9 | Zlobober | 141 |

9 | adamant | 141 |

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.

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/23/2018 19:22:55 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|

As

kis small here. You can do DP with states —DP(u,k) = number of nodes in subtree ofuat distancek. Then you need to combine answers for subtrees. ComplexityO(nk). (Notice that we are not interested in any path of length >k)However this problem can also be solved in

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

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

The graph isn't a tree.

Auto comment: topic has been updated by EBAD (previous revision, new revision, compare).Are negative weights allowed?