7std::vector<int> topoSortKahn(
int N,
const std::vector<std::vector<int> > &adj);
10 int nodes = 0, edges = 0;
11 std::cin >> edges >> nodes;
12 if (edges == 0 || nodes == 0) {
17 std::vector<std::vector<int> >
graph(nodes);
23 for (
int i = 0; i < edges; i++) {
25 graph[u].push_back(v);
28 std::vector<int> topo = topoSortKahn(nodes,
graph);
30 for (
int i = 0; i < nodes; i++) {
31 std::cout << topo[i] <<
" ";
35std::vector<int> topoSortKahn(
int V,
36 const std::vector<std::vector<int> > &adj) {
37 std::vector<bool> vis(V + 1,
false);
38 std::vector<int> deg(V + 1, 0);
39 for (
int i = 0; i < V; i++) {
40 for (
int j : adj[i]) {
45 for (
int i = 0; i < V; i++) {
51 std::vector<int> arr(V + 1, 0);
57 for (
int i : adj[cur]) {