Skip to main content

Get Started

Start using algorithm snippets in your competitive programming workflow in minutes.

Why C++ Algorithm Snippets?

This library provides 161+ battle-tested algorithm implementations designed for competitive programming. Every algorithm includes automatic snippet generation for VS Code and Vim/Neovim, allowing you to focus on problem-solving rather than implementing common data structures and algorithms from scratch.

Graph Algorithms

Dijkstra, Bellman-Ford, Floyd-Warshall, MST, and tree algorithms

Data Structures

Tries, segment trees, fenwick trees, and advanced structures

String Algorithms

KMP, Rabin-Karp, Aho-Corasick, suffix arrays, and hashing

Math & Number Theory

Prime factorization, GCD, modular arithmetic, and matrix operations

Key Features

Snippet Generation

Automatic snippet generation for VS Code and Vim/Neovim

Contest Templates

Optimized templates for USACO, Google Code Jam, and LeetCode

Debugging Tools

Comprehensive debugging utilities for competitive programming

Fast I/O

Optimized input/output utilities and macros

Quick Example

Get started with Dijkstra’s algorithm in your competitive programming solution:
// Include graph structures
// graph_graph, graph_undigraph

template <typename T>
vector <T> dijkstra(const graph<T> &g, int start) {
    assert(0 <= start && start < g.n);
    priority_queue<link<T>, vector<link<T>>, greater<link<T>>> Q;
    vector<T> dist(g.n, numeric_limits<T>::max());
    dist[start] = static_cast<T>(0);
    Q.push({start, static_cast<T>(0)});
    while (!Q.empty()) {
        link<T> node = Q.top(); Q.pop();
        int to = node.to;
        if(node.cost > dist[to]) continue;
        for (link<T> neighbor: g.adj[to]) {
            T newCost = dist[to] + neighbor.cost;
            if (newCost < dist[neighbor.to]) {
                Q.push({neighbor.to, newCost});
                dist[neighbor.to] = newCost;
            }
        }
    }
    return dist;
}

Explore the Library

Installation

Set up snippet generation

Algorithms

Browse all algorithms

API Reference

Complete API documentation

Build docs developers (and LLMs) love