text
stringlengths
2
104M
meta
dict
#pragma once #include <bits/stdc++.h> #include "HeavyLightDecomposition.h" using namespace std; // Supports path (and subtree) updates and queries on a forest // Vertices and indices are 0-indexed // Template Arguments: // R: struct supporting range updates and queries on indices // Required Fields: // Dat...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "LowestCommonAncestor.h" using namespace std; // Supports vertex updates and path queries for invertible operations on // a forest // Vertices and indices are 0-indexed // Template Arguments: // R: struct supporting point updates and range queries on indices // Re...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/FischerHeunStructure.h" using namespace std; // Supports queries for the lowest common ancestor of 2 vertices in a forest // and the distance between 2 vertices by reduing the problem to a // range minimum query using the Fischer Heun Structure /...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Supports subtree updates and queries on a forest // Vertices and indices are 0-indexed // Template Arguments: // R: struct supporting range updates and queries on indices // Required Fields: // Data: the data type // Lazy: the lazy type //...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "LowestCommonAncestor.h" using namespace std; // Supports path updates and vertex queries for invertible operations on // a forest // Vertices and indices are 0-indexed // Template Arguments: // R: struct supporting range updates and point queries on indices // Re...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/BitPrefixSumArray.h" #include "LowestCommonAncestor.h" using namespace std; // Wavelet Matrix supporting 2D aggregation path queries for invertible // operations on a forest where the data can change, but not the keys // Vertices are 0-indexed // T...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Decomposes a tree into chains, such that a path from any vertex to the root // will cover at most O(log V) chains // Can be used with PathQueries for path queries // Vertices and indices are 0-indexed // Constructor Arguments: // G: a generic forest dat...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "LowestCommonAncestor.h" using namespace std; // Mo's algorithm on a tree to answer offline queries over paths on a forest // where each vertex has a value provided by an array A // Template Arguments: // S: struct to maintain a multiset of the elements in a set // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "HeavyLightDecomposition.h" using namespace std; // Supports path (and subtree) queries on a forest // Vertices and indices are 0-indexed // Template Arguments: // R: struct supporting range queries on indices // Required Fields: // Data: the data type // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/FischerHeunStructure.h" #include "../../datastructures/unionfind/WeightedUnionFind.h" using namespace std; // Converts a tree or forest into a line graph to query for the maximum edge // value on a path between two vertices // Vertices are 0-indexe...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/BitPrefixSumArray.h" #include "HeavyLightDecomposition.h" using namespace std; // Wavelet Matrix supporting 2D aggregation path queries using heavy light // decomposition on a forest where the data can change, but not the keys // Vertices are 0-ind...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "LowestCommonAncestor.h" #include "SubtreeQueries.h" using namespace std; // Supports online queries for the number of distinct elements in a // subtree for a static forest G with V vertices // Vertices are 0-indexed // Template Arguments: // T: the type of each eleme...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/trees/fenwicktrees/FenwickTree1D.h" #include "LowestCommonAncestor.h" #include "SubtreeQueries.h" using namespace std; // Supports online queries for the number of distinct elements in a // subtree for a forest G with V vertices with vertex updates...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/BitPrefixSumArray.h" #include "LowestCommonAncestor.h" using namespace std; // Wavelet Matrix supporting rank and select operations for paths on a forest // Vertices are 0-indexed // Template Arguments: // T: the type of the element of the array //...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Supports queries on graphs that involve the set of vertices in a subtree // Template Arguments: // S: struct to maintain a multiset of the elements in a set // Required Fields: // T: the type of each element // R: the type of the return value fo...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Finds the centroid of each component of a tree, // and recursively splits the component at that vertex // Can be used to create a centroid tree, which has depth O(log V) // Function Arguments: // G: a generic forest structure // Required Functions: ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include <ext/pb_ds/priority_queue.hpp> using namespace std; using namespace __gnu_pbds; // Computes the global minimum cut for a weighted graph // A cut is a partition of the vertices into two nonempty subsets // A crossing edge is an edge with endpoints in both subsets // The co...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the global minimum cut for a weighted graph // A cut is a partition of the vertices into two nonempty subsets // A crossing edge is an edge with endpoints in both subsets // The cost of a cut is the sum of the weights of the crossing edges // Verti...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the strongly connected components of a directed graph using // Tarjan's algorithm // Vertices are 0-indexed // Constructor Arguments: // G: a generic directed graph structure which can be weighted or unweighted, // though weights do not c...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFind.h" using namespace std; // Support online queries for the number of bridges in a graph, after edges // have been added // Constructor Arguments: // V: the number of vertices in the graph // Fields: // bridgeCnt: the current ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Decomposes an undirected graph into 2-edge connected components and // identifies bridges // Vertices are 0-indexed // Constructor Arguments: // G: a generic undirected graph structure // Required Functions: // operator [v] const: iterates ove...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFindUndo.h" #include "../../queries/LIFOSetDivAndConq.h" using namespace std; // Support offline queries on connected components, after edges have been // added or removed, using divide and conquer // Constructor Arguments: // V: t...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../dynamictrees/LinkCutTree.h" using namespace std; // Support offline queries on connected components, after edges have been // added or removed, using a Link Cut Tree // Constructor Arguments: // V: the number of vertices in the graph // Fields: // ans: a vector ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFind.h" using namespace std; // Computes the connected components of a graph using Union Find // Vertices are 0-indexed // Constructor Arguments: // V: number of vertices in the graph // Fields: // id: a vector of the index of the ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFind.h" #include "../../datastructures/unionfind/PartiallyPersistentUnionFind.h" using namespace std; // Supports persistent queries on 2-edge connected component after // edges have been added // Constructor Arguments: // V: numbe...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../dynamictrees/LinkCutTree.h" using namespace std; // Support offline queries for the number of bridges in a graph, after edges // have been added or removed, using a Link Cut Tree // Constructor Arguments: // V: the number of vertices in the graph // Fields: // a...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFind.h" using namespace std; // Decomposes an undirected graph into 3-edge connected components // Vertices are 0-indexed // Constructor Arguments: // G: a generic undirected graph structure // Required Functions: // operat...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../dynamictrees/LinkCutTree.h" using namespace std; // Support queries for the number of bridges in a graph, after edges have been // added, using a Link Cut Tree, as well as undoing the last edge added // Constructor Arguments: // V: the number of vertices in the gr...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the biconnected components of an undirected graph // Vertices are 0-indexed // Constructor Arguments: // G: a generic undirected graph structure // Required Functions: // operator [v] const: iterates over the adjacency list of vertex v ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/trees/binarysearchtrees/Splay.h" using namespace std; // Support online queries on connected components, after edges have been // added or removed, using a level structure (log V Euler Tour Trees) // Constructor Arguments: // V: the number of ver...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFind.h" using namespace std; // Computes the minimum spanning tree (or forest) using Kruskal's algorithm // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges // Constructor Arguments: // V: num...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the minimum spanning tree (or forest) using Prims's algorithm // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges // Constructor Arguments: // G: a generic weighted graph structure // Required Function...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFind.h" using namespace std; // Computes the minimum spanning tree (or forest) using Boruvka's algorithm // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges // Constructor Arguments: // V: num...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/trees/heaps/SkewHeapIncremental.h" #include "../../datastructures/unionfind/UnionFindUndo.h" using namespace std; // Computes the minimum arborescence, or directed minimum spanning tree using // Gabow's variant of Edmonds' algorithm // The directed...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/unionfind/UnionFindUndo.h" using namespace std; // Support offline queries for the minimum spanning tree, after edges have been // added or removed, using divide and conquer and UnionFindUndo // Template Arguments: // T: the type of the weight of...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../dynamictrees/LinkCutTree.h" using namespace std; // Supports queries for the minimum spanning tree (or forest) after // edges have been added, using a Link Cut Tree // Template Arguments: // T: the type of the weight of the edges // Constructor Arguments: // V: ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../dynamictrees/LinkCutTree.h" using namespace std; // Supports queries for the minimum spanning tree (or forest) after // edges have been added, using a Link Cut Tree, as well as undoing the // last edge added // Template Arguments: // T: the type of the weight of...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the minimum spanning tree (or forest) using Classical Prims's // algorithm // Vertices are 0-indexed // Constructor Arguments: // G: a generic weighted graph structure // with the [] operator (const) defined to iterate over the adjacency li...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "KruskalMST.h" using namespace std; // Computes the minimum spanning tree of a complete graph of N points where // the edge weights is equal to the Manhattan distance between the // points |x_i - x_j| + |y_i - y_j| // Generates up to 4N candidate edges with each point...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "IncrementalBipartiteUndo.h" #include "../../queries/LIFOSetDivAndConq.h" using namespace std; // Support offline queries on connected components and bipartiteness, after // edges have been added or removed, using divide and conquer // Constructor Arguments: // V: the...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Supports queries for whether a graph component is bipartite // after edges have been added using Union Find by size supporting undos // Vertices are 0-indexed // V: the number of vertices in the graph // Fields: // UF: a vector of integers representin...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Supports queries for whether a graph component is bipartite // after edges have been added using Union Find by size with path compression // Vertices are 0-indexed // V: the number of vertices in the graph // Fields: // UF: a vector of integers repres...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Determines whether an undirected graph is bipartite, or whether it has // an odd cycle // Vertices are 0-indexed // Constructor Arguments: // G: a generic undirected graph structure // Required Functions: // operator [v] const: iterates over t...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the dominator tree rooted at a vertex // A vertex dominates v another vertex w if all paths from the root to w must // pass through v // A vertex v is an immediate dominator of w if v dominates w and no other // vertex dominates w // Vertices a...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Recursive helper function template <const int MAXV, class F> void maximalCliques(const vector<bitset<MAXV>> &matrix, F &f, bitset<MAXV> P, bitset<MAXV> X, bitset<MAXV> R) { if (!P.any()) { if (!X.any()) f(R); return; } auto...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../components/StronglyConnectedComponents.h" using namespace std; // Solves the two satisfiability problem and provides all possible values // for each variable // Given an implication graph, determine whether a consistent assignment exists // Functions for created an ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Finds small minimum vertex covers // Vertices are 0-indexed // Constructor Arguments: // V: the number of vertices in the graph // e: a vector of pairs in the form (v, w) representing // an undirected edge in the simple graph (no self loops or paral...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Functions for generating an implication graph // Each function runs a callback on the created edges // N variables will require a graph with N * 2 vertices, with vertex // a * 2 + 1 representing the affirmative for variable a, and a * 2 // representing ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../components/StronglyConnectedComponents.h" using namespace std; // Solves the two satisfiability problem // Given an implication graph, determine whether a consistent assignment exists // Functions for created an implication graph can be seen in ImplicationGraph.h // V...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Modified from https://github.com/kth-competitive-programming/kactl/blob/master/content/graph/MaximumClique.h, // which itself is based on // https://gitlab.com/janezkonc/mcqd/blob/master/mcqd.h, // which has a GPL3 license // Computes the clique with ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the maximum weighted matching in a general undirected weighted // graph, such that each vertex is incident with at most one edge in the // matching, and the selected edges have the maximum sum of weights // Vertices are 0-indexed // Template Ar...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Given N people of type A and M people of type B, and a list of their ranked // preferences for partners, the goal is to arrange min(N, M) pairs such that // if a person x of type A prefers a person y of type B more than their // current partner, then ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the assignment problem of matching N workers to M jobs with the // minimum cost where each worker can only be assigned to at most 1 job and // each job can only be assigned to at most 1 worker and there are exactly // min(N, M) assignments // M...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the maximum matching in a general undirected graph, such that each // vertex is incident with at most one edge in the matching // Vertices are 0-indexed // Constructor Arguments: // G: a generic undirected graph structure // Required Functi...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Given N people, and a list of their ranked preferences for roommates, // the goal is to arrange N / 2 pairs such that if a person x prefers // a person y more than their current roommate, then person y prefers // their current roommate more than x // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the maximum matching (and minimum vertex cover) on // an unweighted bipartite graph // The maximum independent set is any vertex not in the minimum vertex cover // Vertices are 0-indexed // Constructor Arguments: // G: a generic undirected bipa...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Floyd Warshall's all pairs shortest path algorithm for weighted graphs // with negative weight // Able to detect negative cycles // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges in the graph // Constructor Argum...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Bellman Ford's single source shortest path algorithm for weighted graphs // with negative weights // Able to detect negative cycles // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges in the graph // Constructor Ar...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../datastructures/trees/heaps/PersistentRandomizedHeap.h" using namespace std; // Computes the K shortest walks from s to t in a directed graph // Template Arguments: // T: the type of the weight of the edges // Function Arguments: // V: number of vertices in the ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the shortest Hamiltonian cycle // All vertices are visited exactly once before returning to the start vertex // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges in the graph // Constructor Arguments: // ma...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../search/TransitiveClosureSCC.h" using namespace std; // Johnson's all pairs shortest path algorithm for weighted graphs // with negative weights // Able to detect negative cycles // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the e...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../search/TopologicalOrder.h" using namespace std; // Computes the shortest path (based on the comparator) on a directed // acyclic graph // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges in the graph // Cmp: the comparator ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Classical Dijkstra's single source shortest path algorithm for // weighted graphs without negative weights // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges in the graph // Constructor Arguments: // G: a generi...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the shortest Hamiltonian path // All vertices are visited exactly once, does not return to the start // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges in the graph // Constructor Arguments: // matrix: a...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Dijkstra's single source shortest path algorithm for weighted graphs // without negative weights // Vertices are 0-indexed // Template Arguments: // T: the type of the weight of the edges in the graph // Constructor Arguments: // G: a generic weighted...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point3D.h" #include "Sphere3D.h" using namespace std; // Functions for a 3D polyhedron // Determines twice the vector area of a face of coplanar points // Function Arguments: // face: the coplanar points of the face // Return Value: twice the vector area of the face, ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../utils/EpsCmp.h" using namespace std; // Functions for a 3D point // * operator between 2 points is cross product // | operator between 2 points is dot product #define OP(op, U, a, x, y, z) \ pt3 operator op (U a) const { return pt3(x, y, z); } \ pt3 &operator o...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../utils/Random.h" #include "Point3D.h" using namespace std; // Computes the convex hull of a set of N points 3D points (convex set of // minimum points with the minimum volume) // Function Arguments: // P: the vector of points // Return Value: a vector of faces i...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point3D.h" using namespace std; // Affine Transformations in 3D // Functions: // prependMatrix(m2, b2): sets m = m2 * m and b = m2 * b + b2 // transform(t): applies the AffineTransformation t to this // scale(p): scales the x, y, z coordinates by p.x, p.y, p.z resp...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point3D.h" #include "Line3D.h" using namespace std; // Functions for a 3D plane struct Plane3D { pt3 n; T d; // ax + by + cz = d, above is ax + by + cz > d Plane3D(T a = 0, T b = 0, T c = 0, T d = 0) : n(a, b, c), d(d) {} // normal n, offset d Plane3D(pt3 n, T ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point3D.h" #include "Line3D.h" #include "Plane3D.h" using namespace std; // Functions for a 3D sphere struct Sphere3D { pt3 o; T r; Sphere3D(T r = 0) : o(0, 0), r(r) {} Sphere3D(pt3 o, T r) : o(o), r(r) {} // 1 if p is inside this sphere, 0 if on this sphere, // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point3D.h" using namespace std; // Functions for a 3D plane (represented in parametric form o + kd for real k) struct Line3D { pt3 o, d; // points p and q Line3D(pt3 p = pt3(0, 0, 0), pt3 q = pt3(0, 0, 0)) : o(p), d(q - p) {} bool onLine(pt3 p) const { return eq(...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../utils/Random.h" #include "Point.h" #include "Circle.h" using namespace std; // Determines the minimum enclosing circle of a set of points // Function Arguments: // P: the points // Return Value: the minimum enclosing circle of P // In practice, has a large consta...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Angle.h" using namespace std; // Computes the minimum area from 3 distinct points out of a set of N points // Angle::pivot is modified // Constructor Arguments: // P: the vector of points // Fields: // PA: the first point in the minimum area triang...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Computes the Delaunay Triangulation of a set of distinct points // If all points are collinear, there is no triangulation // If there are 4 or more points on the same circle, the triangulation is // ambiguous, otherwise it is unique // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Line.h" using namespace std; // Helper struct for bentleyOttmann struct Seg { static T X; mutable pt p, q; mutable int i; bool isQuery; pair<T, T> y() const { pt v = q - p; return make_pair(cross(v, p) + v.y * X, v.x); } Seg(pt p, pt q, int...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Supports adding lines in the form f(x) = mx + b, or line segments // in the form of f(x) = mx + b over l <= x <= r, and finding // the maximum value of f(x) where all possible value of x are // known beforehand // Template Arguments: // T: the type ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Angle.h" #include "Line.h" using namespace std; // Computes the intersection of half-planes defined by the left side of // a set of lines (including the line itself) // Points on the intersection are given in ccw order and may be identical // Angle::...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Supports adding lines in the form f(x) = mx + b, or line segments // in the form of f(x) = mx + b over l <= x <= r, and finding // the maximum value of f(x) at an integral point x where MN <= x <= MX // Template Arguments: // IndexType: the type of x ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "ConvexHull.h" using namespace std; // Computes the maximmum area from 3 distinct points out of a set of N points // Constructor Arguments: // P: the vector of points // Fields: // PA: the first point in the maximum area triangle // PB: the second...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Angle.h" #include "Line.h" #include "Circle.h" using namespace std; // Functions for 2D polygons, represented by a vector of the N points in // the polygon // Returns i mod n if i is in the range [0, 2n) int mod(int i, int n) { return i < n ? i : i ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../search/BinarySearch.h" using namespace std; // Supports adding lines in the form f(x) = mx + b and finding // the maximum value of f(x) at any given x; this version allows for // updates and queries in arbitrary order // Template Arguments: // T: the type of ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Angle.h" #include "Line.h" #include "Circle.h" using namespace std; // A ray represented by a point and line with a direction // Fields: // p: the point // l: a line passing through p, representing the direction // nxt: a pointer to the next ray ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../search/BinarySearch.h" using namespace std; // Supports adding lines in the form f(x) = mx + b and finding // the maximum value of f(x) at any given x; this version only supports // adding lines in sorted order // Template Arguments: // T: the type of the slo...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Angle.h" #include "Line.h" #include "../../datastructures/IntervalUnion.h" using namespace std; // Functions for a 2D circle struct Circle { pt o; T r; Circle(T r = 0) : o(0, 0), r(r) {} Circle(pt o, T r) : o(o), r(r) {} // 1 if p is inside this ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Helper struct for IncrementalConvexHullTrick template <class T> struct CHTLine { bool isQuery; T m, b; mutable T x; CHTLine(T m, T b) : isQuery(false), m(m), b(b), x(T()) {} CHTLine(T x) : isQuery(true), m(T()), b(T()), x(x) {} }; // Supports adding ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Angle.h" #include "Line.h" using namespace std; // Helper struct for polygonTriangulation struct Chain { static T X; mutable Line l; Chain(T Y) : l(0, 1, Y) {} Chain(pt p, pt q) : l(p, q) {} bool operator < (const Chain &c) const { return l...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Computes the convex hull of a set of N points // Function Arguments: // P: the vector of points // Return Value: a vector of points in the convex hull in ccw order // In practice, has a small constant // Time Complexity: O(N log N) // M...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Computes the closest pair of points out of a set of N points // Constructor Arguments: // P: the vector of points // Fields: // best1: the first point in the pair of closest points // best2: the second point in the pair of closest p...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "ConvexHull.h" using namespace std; // Computes the farthest pair of points out of a set of N points // Constructor Arguments: // P: the vector of points // Fields: // best1: the first point in the pair of farthest points // best2: the second poin...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Functions for a 2D line struct Line { pt v; T c; // ax + by = c, left side is ax + by > c Line(T a = 0, T b = 0, T c = 0) : v(b, -a), c(c) {} // direction vector v with offset c Line(pt v, T c) : v(v), c(c) {} // points p and ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Kd Tree for randomized 2d points // Constructor Arguments: // xmin: the minimum x value // ymin: the minimum y value // xmax: the maximum x value // ymax: the maximum y value // P: the points // Functions: // empty(): returns ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Struct to compare angles in the range [-PI, PI) around a pivot based // on arg(p - pivot) // Points directly to the left have an angle of -PI, points equal to the pivot // are placed after all points // Constructor Arguments: // p: ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" #include "Circle.h" #include "DelaunayTriangulation.h" using namespace std; // Computes the Voronoi Diagram and Delaunay Triangulation of a set of // distinct points // If all points are collinear, there is no triangulation or diagram // If there are 4 or more...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Affine Transformations in 2D // Functions: // prependMatrix(m2, b2): sets m = m2 * m and b = m2 * b + b2 // transform(t): applies the AffineTransformation t to this // scale(p): scales the x and y coordinates by p.x and p.y respecti...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "Point.h" using namespace std; // Helper struct to maintain upper hull struct DecrementalUpperHull { struct Link; using ptr = Link *; struct Link { int id; pt p; ptr prv, nxt; Link(int id, pt p) : id(id), p(p), prv(nullptr), nxt(nullptr) {} }; struct Node ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../search/BinarySearch.h" using namespace std; // Supports adding lines in the form f(x) = mx + b, finding // the maximum value of f(x) at any given x, and removing the last line added // Template Arguments: // T: the type of the slope (m) and intercept (b) of the...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../../utils/EpsCmp.h" using namespace std; // Functions for a 2D point // * operator between 2 points is complex number multiplication // / operator between 2 points is complex number division #define OP(op, U, a, x, y) pt operator op (U a) const { return pt(x, y); } \ ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Binary search over a range for the first or last occurrence of // a return value for a boolean function // Template Arguments: // ISFIRST: boolean of whether or not the first of last occurrence is being // searched for // T: the type of the range ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Ternary search for the maximum of a function // Template Arguments: // T: the type of the range to search over, must be a floating point type // F: the type of the function that is being searched over // Cmp: the comparator to compare two f(x) values,...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }