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

2 | OO0OOO00O0OOO0O0…O | 3327 |

3 | Petr | 3161 |

4 | LHiC | 3158 |

5 | CongLingDanPaiSh…5 | 3116 |

6 | ko_osaga | 3115 |

7 | mnbvmar | 3111 |

8 | Um_nik | 3104 |

9 | Benq | 3098 |

10 | Swistakk | 3089 |

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

1 | Radewoosh | 185 |

2 | Errichto | 163 |

3 | rng_58 | 161 |

4 | tourist | 158 |

5 | Vovuh | 150 |

5 | Um_nik | 150 |

7 | Swistakk | 149 |

7 | Petr | 149 |

9 | PikMike | 148 |

10 | 300iq | 147 |

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: Oct/16/2018 20:47:17 (f1).

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?