// 拓扑排序
// 利用set保证输出时队伍号小的在前
#include <iostream>
#include <set>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
#define MAXN 505
set<int> winner;
int in[MAXN];
int main(){
int n, m;
int cnt;
int del;
while(cin >> n >> m){
memset(in, 0, sizeof(in));
vector<int> adj[MAXN];
cnt = n;
int a, b;
while(m--){
cin >> a >> b;
in[b] ++;
adj[a].push_back(b);
}
for(int i = 1; i <= n; i++)
if(in[i] == 0)
winner.insert(i);
while(cnt){
set<int>::iterator it = winner.begin();
del = *it;
winner.erase(it);
cnt--;
cout << del;
if(cnt != 0)
cout << ' ';
for(int i = 0; i < adj[del].size(); i++){
in[adj[del][i]] --;
if(in[adj[del][i]] == 0)
winner.insert(adj[del][i]);
}
}
cout << endl;
}
return 0;
}
HDU 1285 确定比赛名次
最新推荐文章于 2024-07-04 16:16:29 发布