--- id: toposort title: "Topological Sort" author: Benjamin Qi prerequisites: - - Gold - Breadth First Search --- A [topological sort](https://en.wikipedia.org/wiki/Topological_sorting) of a directed graph is a linear ordering of its vertices such that for every directed edge $u\to v$ from vertex $u$ to vertex $v$, $u$ comes before $v$ in the ordering. ## Example Problems - [CSES Course Schedule](https://cses.fi/problemset/task/1679) - [CSES Longest Flight Route](https://cses.fi/problemset/task/1680) - [CSES Game Routes](https://cses.fi/problemset/task/1681) ## Tutorial - CPH 16.1, 16.2 - DFS - [cp-algorithms](https://cp-algorithms.com/graph/topological-sort.html) - DFS - [CSAcademy](https://csacademy.com/lesson/topological_sorting) - both BFS, DFS ## Problems - USACO Gold - [Timeline](http://www.usaco.org/index.php?page=viewproblem2&cpid=1017) - [Milking Order](http://www.usaco.org/index.php?page=viewproblem2&cpid=838) - Other - [Minimal Labels](http://codeforces.com/contest/825/problem/E) [](53) - [Quantum](https://open.kattis.com/contests/acpc17open/problems/quantumsuperposition) [](84)