Tree Problem Summary

Introduction During the summer vacation, I systematically studied various operations on trees through Teacher Tuo's sharing and discovered many useful techniques, which I now summarize. Teacher Tuo is amazing! One Problem Type: Batch processing queries of the form f(dep(lca(x,y))), where f(x) is a function of x. Approach: First perform tree ...

Posted on Sat, 01 Aug 2026 16:21:20 +0000 by D_tunisia

Graph Algorithms and Critical Path Analysis in C

Depth-First Search on Adjacency-Matrix Graphs void DFS(MGraph G, Vertex v, void (*visit)(Vertex)) { visit(v); Visited[v] = true; for (Vertex w = 0; w < G->Nv; ++w) if (G->G[v][w] && !Visited[w]) DFS(G, w, visit); } Breadth-First Search on Adjacency-List Graphs void BFS(LGraph G, Vertex s, void ...

Posted on Wed, 22 Jul 2026 16:36:11 +0000 by han2754

Determining Graph Connectivity using DFS and BFS

Algorithmic Approach When handling graph problems, especially those involving large datasets, an adjacency list is often preferred over an adjacency matrix to optimize memory usage, particularly when the vertex count may exceed standard limits. To determine if an undirected graph is connected, one can traverse the structure using either Depth-F ...

Posted on Sun, 19 Jul 2026 16:48:56 +0000 by Jay87

Solutions for 2024 RoboCom CAIP Programming Skills Provincial Competition

RC-u1 Heat Wave Problem Summary: Given daily maximum temperatures and the day of the week for the first day, count how many days have temperatures ≥ 35°C. Days falling on weekends (Saturday and Sunday) should be counted separately. Solution: Iterate through the temperature data while tracking the current weekday. For each temperature ≥ 35, incr ...

Posted on Tue, 07 Jul 2026 17:58:05 +0000 by [UW] Jake

Search Algorithms in Problem Solving

Definition Search algorithms systematically explore state spaces to find optimal solutions or count valid configurations through exhaustive enumeration. This approach leverages understanding of state transitions to navigate possible states. Search Algorithm Applications When explicit enumeration becomes infeasible (e.g., permutations for n=100 ...

Posted on Thu, 02 Jul 2026 17:04:03 +0000 by littlejones

Graph Traversal: Searching References

Problem Description Little K enjoys browsing Luogu blog articles for knowledge. Each article may have several (or none) reference links pointing to other blog articels. Little K is very curious: if he reads an article, he will certainly read its references (unless he has already read that reference). Assume there are n (n ≤ 10^5) articles on Lu ...

Posted on Wed, 01 Jul 2026 16:36:22 +0000 by coder4Ever

Implementing Inorder Traversal for Binary Trees

To retrieve node values from a binary tree in ascending order (for a BST) or the standard left-root-right sequence, a recursive approach works cleanly. The traversal explores the left subtreee first, records the current node, then visits the right subtree. Below are Python implementations that illustrate this technique. class TreeNode: def ...

Posted on Mon, 29 Jun 2026 17:39:32 +0000 by patrikG

Understanding Simulation, DFS/BFS, Dynamic Programming, and Block Decomposition for Competitive Programming

Simulation problems, often labeled as "warm-up" or "signature" tasks in contests, require translating problem statements directly into code without relying on predefined algorithms. While they appear simple, their difficulty lies in accurately interpreting edge cases and constraints. A single oversight in boundary checks or ...

Posted on Sun, 14 Jun 2026 16:51:10 +0000 by ldougherty

Binary Tree Algorithms: Bottom-Left Value, Path Sum Variants, and Tree Construction from Traversals

Finding the Bottom-Left Node Value Given the root of a binary tree, return the value of the leftmost node at the deepest level. Breadth-First Search (Iterative) A level-order traversal naturally visits nodes layer by layer. The first node encountered in the final level is the answer. #include <queue> int findBottomLeftValue(TreeNode* roo ...

Posted on Sat, 13 Jun 2026 17:35:17 +0000 by eideticmnemonic

Solving Problems ABC 269 (A-G)

A: Basic Arithmetic and Output Given integers a, b, c, d, compute (a + b) * (c - d) and output the result followed by the string "Takahashi". int a = input(), b = input(), c = input(), d = input(); cout << (a + b) * (c - d) << endl; cout << "Takahashi" << endl; Time complexity: O(1) B: Finding Corne ...

Posted on Wed, 10 Jun 2026 16:36:46 +0000 by Elephant