# 逃生

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

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

Source

Recommend
We have carefully selected several similar problems for you:  5566 5565 5564 5563 5562

#include<stdio.h>
#include<string.h>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int u;
int v;
int next;
}t[110000];
void topo()
{
int i,c=0;
priority_queue<int>q;
for(i=1;i<=m;i++)
if(!dig[i])
q.push(i);
while(!q.empty())
{
int x=q.top();
q.pop();
ans[c++]=x;
{
int y=t[i].v;
dig[y]--;
if(dig[y]==0)
q.push(y);
}
}
for(i=m-1;i>0;i--)
printf("%d ",ans[i]);
printf("%d\n",ans[i]);
}
int main()
{
scanf("%d",&k);
while(k--)
{
memset(ans,0,sizeof(ans));
memset(dig,0,sizeof(dig));
scanf("%d%d",&m,&n);
cnt=0;
for(i=0;i<n;i++)
{
scanf("%d%d",&v,&u);
t[cnt].u=u;
t[cnt].v=v;
dig[v]++;
}
topo();
}
}

03-12 413

07-22 1816

08-06 268

08-05 201

08-07 422

08-06 159

07-20 1395

06-04 170

08-05 180

08-06 90