Загрузка...

C++ Program | Update Edge Weights, Find Shortest Path in Tree | Segment Tree + Heavy Light Decompo.

In this video, we solve a challenging C++ coding problem based on trees and queries.
We are given a weighted tree rooted at node 1 and need to handle two types of queries:

1️⃣ Update Query → Update the weight of an edge between two nodes.
2️⃣ Shortest Path Query → Find the shortest path from the root (node 1) to a given node.

We use Heavy Light Decomposition (HLD) with a Segment Tree to handle updates and queries efficiently in O(log² n).

📚 Concepts Covered

Tree representation in C++

Depth, parent, subtree size computation using DFS

Heavy Light Decomposition (HLD)

Segment Tree for path queries and edge updates

Handling online queries efficiently

🚀 Time Complexity:

Build: O(n)

Each query: O(log² n)

This problem is very useful for competitive programming and coding interviews.
#cplusplus #dsa #competitiveprogramming #codinginterview #segmenttree #heavylightdecomposition #treeproblems #shortestpath #cppcoding #dsaproblems #leetcode #codeforces #codingtheoryguru

Видео C++ Program | Update Edge Weights, Find Shortest Path in Tree | Segment Tree + Heavy Light Decompo. канала Coding theory
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять