Untitled
unknown
plain_text
a month ago
441 B
4
Indexable
Never
vector<int> adj[MAX]; // Danh sách kề vector<bool> visited(MAX, false); vector<int> topo; void dfs(int v) { visited[v] = true; for (int u : adj[v]) { if (!visited[u]) { dfs(u); } } topo.push_back(v); } void topological_sort(int n) { for (int i = 0; i < n; i++) { if (!visited[i]) { dfs(i); } } reverse(topo.begin(), topo.end()); }
Leave a Comment