category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

kind of topological sorting

D - Restricted Permutation, Hard

Sample Code ```cpp int n, m; cin >> n >> m; std ::vector<std ::vector> graph(n + 1); std ::vector indegree(n + 1); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); indegree[b]++; } priority_queue<int, std ::vector, std::greater> pq; for (int i = 1; i <= n; i++) if (indegree[i] == 0) pq.push(i); std ::vector order; while (!pq.empty()) { auto u = pq.top(); pq.pop(); order.push_back(u); for (const auto &v : graph[u]) if (--indegree[v] == 0) pq.push(v); } if (order.size() != n) { cout << "-1\n"; return; } for (const auto &i : order) cout << i << ' '; ``` </details>