#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <climits>
using namespace std;
const int MAXN = 100;
vector<int> graph[MAXN];
int inDegree[MAXN];
vector<int> TopologicalSort(int n){
vector<int> topology;
priority_queue<int ,vector<int>,greater<int>> node;
for (int i = 0; i < n; ++i) {
if (inDegree[i] == 0){
node.push(i);
}
}
while (!node.empty()){
int u = node.top();
node.pop();
topology.push_back(u);
for (int i = 0; i < graph[u].size(); ++i) {
int v = graph[u][i];
inDegree[v]--;
if (inDegree[v]==0){
node.push(v);
}
}
}
return topology;
}
|