This code produces LCA of a given tree using the concept of binary lifting.
This code produces LCA of a given tree using the concept of binary lifting with the use of Ancestors. CONTAINS ERROR!!! FIX IT!!!
-
Given an implication graph, this checks if a solution exists. addXor(), addAnd(), addOr() can be used to appropriately add clauses.
-
forceTrue() forces some variable to be true. forceFalse() forces some variable to be false.
-
You can also add additional implications yourself.
-
solve() checks if in the final implication graph, a valid solution exists.
-
mark[u] stores the boolean value of the node (u). You can use mark[] to recover the final solution as well.
-
Notes on Indexing Nodes : (i) u = 2k, !u = 2k 1 (ii) Nodes are 0-indexed. [0, NUM VERTICES)
This code implements the dijkstra algorithm.
-
This code implements the ford fulkerson algorithm which calculates the Maximum Flow.
-
The nodes are ideally should be numbered as 1-indexed. So, if there are v nodes, the constructor should be given v 1 nodes.
-
Depending upon the problem check out the addEdge function.
-
The time complexity of the algorithm is O(Ef) where E is the number of Edges and f is the maximum flow (Atleast one). The space complexity is O(V^2 E).
-
This code implements the ford fulkerson algorithm which calculates the Maximum Flow.
-
The nodes are ideally should be numbered as 1-indexed. So, if there are v nodes, the constructor should be given v 1 nodes.
-
The time complexity of the algorithm is O(E f log(MAX DEGREE)) where E is the number of Edges and f is the maximum flow (Atleast one). The space complexity is O(V E).
-
This code implements the Hopcroft-Karp algorithm which calculates the Maximal Matching for bipartite graphs.
-
The nodes on the left and right side are both 1-indexed respectively.
-
The time complexity of the algorithm is O(EV^0.5) and the space complexity is O(V E).
-
Problem Source - https://codeforces.com/problemset/problem/220/B
-
You could get the major template of Mo Offline Algorithm in it.
-
Problem Source - https://codeforces.com/contest/868/problem/F
-
Preconditions -
2.1 The DP Expression should be of this form DP[i][j] = MIN(k <= j) {DP[i-1][k] C[k][j]}.
2.2 Let opt(i,j) be the value of k that minimizes the above expression. If opt(i,j)≤opt(i,j 1) for all i,j, then we can apply divide-and-conquer DP.
-
The time complexity is O(n k log n). The Space Complexity is O(n k).
-
Change the update function as per the needs. It doesn't affect the comlexity. This file contains the major template of Divide and Conquer DP Optimization.
- May contain bugs. FIX IT.
-
Articulation Points are printed are sorted in increasing order and so are the edges (u v where u < v) in increasing order with the first vertex and then the second vertex.
-
This helps us encapsulate the concept of DFS Tree.
-
Problem Source - https://www.spoj.com/problems/QTREE/
-
This is an example for Heavy Light Decompostion with queries on edges. This will help you get the template for HLD for edge queries.
-
The difference between Edge based queries and vertex based queries is that we take the information of the edge to the vertex with the larger depth. Then it is just like HLD with vertex queries but with the change that during queries we don't need the LCA. This is clearly seen in the query function of the HeavyLightDecomposition Struct, where the last Segtree query call had in[u] 1 instead of in[u].
-
Problem Source - https://www.spoj.com/OI/problems/QTREE3/ , I couldn't submit the problem. However, I submitted the HLD in some other problem and it got accepted.
-
This is an example for Heavy Light Decompostion with queries on vertices. This will help you get the template for HLD for vertices queries.
- Single Update Segment Tree. Just update the combine function.
- Range Update Segment Tree. Just update the combine function, Node class and propogate.
- Nothing special in this.
- Used when we need to order some elements and there is a dependency between elements i.e. some elements only if other elements are there.
- Will not work if there is a Cycle.
- Add Edges ( u,v ) in graph if v will come only after u comes.
- Longest Increasing Subsequence -> O (N Log N)
- DP Array -> dp [i] = Smallest element ending with LIS of length i-1.
- Used when we need to order some elements and there is a dependency between elements i.e. some elements only if other elements are there.
- Will work if there is a Cycle.
- Add Edges ( u,v ) in graph if v will come only after u comes.
- Iterative Implementation.