253人阅读 评论(0)

# 逃生

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

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<queue>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAX 301000
struct node
{
int u,v;
int next;
}edge[MAX];
int dre[MAX],cnt,d[MAX],ans,m,n;
void add(int u,int v)
{
edge[cnt].u=u;
edge[cnt].v=v;
}
void dijkstra()
{
priority_queue<int>q;
for(int i=1;i<=m;i++)
if(dre[i]==0)
q.push(i);
while(!q.empty())
{
int u=q.top();
q.pop();
d[ans++]=u;
{
int v=edge[i].v;
dre[v]--;
if(dre[v]==0)
q.push(v);
}
}
for(int i=ans-1;i>=1;i--)
printf("%d ",d[i]);
printf("%d\n",d[0]);
}
int main()
{
int a,b;
int t;
scanf("%d",&t);
while(t--)
{
cnt=ans=0;
memset(dre,0,sizeof(dre));
scanf("%d%d",&m,&n);
while(n--)
{
scanf("%d%d",&a,&b);
dre[a]++;
}
dijkstra();
}
return 0;
}

个人资料
等级：
访问量： 16万+
积分： 7700
排名： 3372
最新评论