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 | 3686 |

2 | LHiC | 3330 |

3 | wxhtxdy | 3329 |

4 | Benq | 3315 |

5 | Um_nik | 3301 |

6 | sunset | 3279 |

7 | V--o_o--V | 3275 |

8 | yutaka1999 | 3190 |

9 | Radewoosh | 3179 |

10 | Petr | 3115 |

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

1 | Errichto | 193 |

2 | Radewoosh | 184 |

3 | rng_58 | 163 |

4 | PikMike | 162 |

5 | Vovuh | 159 |

6 | 300iq | 153 |

7 | Petr | 148 |

8 | Um_nik | 147 |

9 | majk | 146 |

10 | neal | 144 |

10 | kostka | 144 |

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-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/18/2019 21:46:17 (g1).

Desktop version, switch to mobile version.

Supported by

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?