Trick | Difficulty | |
---|---|---|
LC 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance | Shortest Path | 5 points |
LC 1462. Course Schedule IV | Shortest Path or BFS (topological sort) | 5 points |
LC 1135. Connecting Cities With Minimum Cost | Minimum Spanning Tree | 5 points |
LC 1102. Path With Maximum Minimum Value | Shortest Path (Customized Cost Function) | 5-6 points |
LC 1168. Optimize Water Distribution in a Village | Minimum Spanning Tree | 6 points |
LC 787. Cheapest Flights Within K Stops | Shortest Path (limit k stops) | 5-6 points |
Category: Graph
Eulerian Path
In graph theory, an Eulerian trail (or Eulerian path) is a trail in a finite graph that visits every edge exactly once (allowing for revisiting vertices). Similarly, an Eulerian circuit or Eulerian cycle is an Eulerian trail that starts and ends on the same vertex. We have the following properties for undirected graph, An undirected graph has an Eulerian cycle if and only if every vertex has even…
LCA (Binary Lifting) Template
Minimum Spinning Tree
Summary A spanning tree of some graph G is a subgraph that is a tree which includes all of the vertices of G, with a minimum possible number of edges. A Minimum Spanning Tree (MST) is a spanning tree whose sum of edge weights is as small as possible. Kruskal’s Algorithm Please refer to this page for its concepts and pseudo codes. The following code…
Eulerian Path
Summary An Eulerian path is a path in a finite graph that visits every edge exactly once (allowing for revisiting vertices). An Eulerian cycle is a Eulerian path that starts and ends on the same vertex. We give the following properties without proof. An undirected graph has an Eulerian trail iif exactly 0 or 2 vertices have odd degree, its…
Lowest Common Ancestor
Summary Lowest Common Ancestor (LCA) is a typical rooted tree related problem. A simple solution is use dfs to traverse the graph from root to leaves. If at some point it is first time we find out two nodes are in the same subtree, the current node is the LCA. The solution costs O(n) time….
Shortest Path
Summary A common problem in undirected or directed graph is to calculate the shortest path between two nodes. There are several typical technologies that we could use. Floyd-Warshall Shortest paths (multiple sources) in such graphs that: It is actually a DP problem. We define alg[k][x][y] as the shortest path from x to y using the…