Topological Sort - YessineJallouli/Competitive-Programming GitHub Wiki
#include <bits/stdc++.h>
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false), cin.tie(0);
using namespace std;
const int N = 3e5+7;
vector<vector<int>> graph(N);
bool visite[N];
bool act[N];
deque<int> res;
bool cycle = false;
void topsort(int node) {
if (visite[node])
return;
visite[node] = true;
act[node] = true;
for (int ch : graph[node]) {
if (act[ch])
cycle = true;
topsort(ch);
}
act[node] = false;
res.push_front(node);
}
int main() {
SaveTime
}
Resources :
https://youtu.be/L2mnGv6ydYA from minute 36
Problems :
https://codeforces.com/contest/510/problem/C