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

2 | Radewoosh | 3468 |

3 | Um_nik | 3429 |

4 | Petr | 3354 |

5 | Benq | 3286 |

6 | mnbvmar | 3280 |

7 | wxhtxdy | 3276 |

7 | LHiC | 3276 |

9 | ecnerwala | 3214 |

10 | yutaka1999 | 3190 |

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

1 | Errichto | 191 |

2 | Radewoosh | 179 |

3 | tourist | 172 |

4 | Vovuh | 165 |

4 | PikMike | 165 |

4 | antontrygubO_o | 165 |

7 | rng_58 | 160 |

8 | majk | 156 |

8 | Um_nik | 156 |

10 | 300iq | 155 |

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: Oct/18/2019 15:52:30 (e1).

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?