# 逃生

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4265    Accepted Submission(s): 1185

Problem Description

Input

Output

Sample Input
1 5 10 3 5 1 4 2 5 1 2 3 4 1 4 2 3 1 5 3 5 1 2

Sample Output
1 2 3 4 5

Author
CLJ

priority_queue有三个参数，如果最后两个缺省，默认按照大顶堆的方式平排，将最大的元素拿到对头。每次从最大元素开始取。如果有特殊安排，只有当小的元素被取出后大元素的度数变为零才可以进队列后排在对头出队列。

#include <cstdio>
#include <cstring>
#include <queue>
#define MAXN 100002
using namespace std;
struct node{
int to, next;
}edge[MAXN];
int t, n, m, a, b;
void solved() {
//大顶堆排序
priority_queue<int> que;
int u, id = 1;
for(int i = 1; i <= n; i++)
if(!indegree[i]) que.push(i);
while(!que.empty()){
ans[id++] = u = que.top(); que.pop();
for(int i = head[u]; i != -1; i = edge[i].next) {
if(!--indegree[edge[i].to])
que.push(edge[i].to);
}
}
for(int i = n; i >= 1; i--) {
if(i != 1) printf("%d ", ans[i]);
else printf("%d\n", ans[i]);
}
}
int main() {
scanf("%d", &t);
while (t--) {
memset(indegree, 0, sizeof(indegree));
scanf("%d%d", &n, &m);
for(int i = 0; i < m; i++){
scanf("%d%d", &a, &b);
edge[i].to = a; edge[i].next = head[b];
}