Help with the approach and code in C++. Thanks I have tried Dijkstra by make every edge weights to -1. But I am not able to print the longest path.

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

1 | Benq | 3797 |

2 | tourist | 3723 |

3 | Radewoosh | 3720 |

4 | ecnerwala | 3579 |

5 | ksun48 | 3463 |

6 | Um_nik | 3457 |

7 | maroonrk | 3446 |

8 | jiangly | 3432 |

9 | Petr | 3370 |

10 | scott_wu | 3350 |

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

1 | 1-gon | 208 |

2 | awoo | 185 |

3 | rng_58 | 184 |

4 | Errichto | 182 |

5 | SecondThread | 177 |

6 | Radewoosh | 176 |

6 | maroonrk | 176 |

6 | -is-this-fft- | 176 |

9 | Um_nik | 173 |

10 | antontrygubO_o | 170 |

Hi, I was going through the solutions for this question Mike and Distributions and wrote this ->Solution<- using some hints from some others solution.

Help me, I can't figure out why this solution even passes as it would have given TLE. Thanks in advance.

I can't understand the solutions of Query on trees https://www.codechef.com/COMA2020/problems/QUERYT . Help me with the concept and Solution.

Question: You are given a tree with N nodes and N−1 edges. The nodes are numbered from 1 to N and the tree is rooted at 1.

Every node has a value associated with it.

If we consider the simple path between two nodes u and v , then a node in this path is called special if it's value is not coprime with the value of lca(u,v). Here lca(u,v) means the lowest common ancestor of u and v.

You will be given Q queries. Every query contains two integers denoting two nodes,u and v. You have to find the count of special nodes in the simple path between u and v.

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/20/2021 03:56:21 (g2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|