problem
solution
codes
#include<iostream>
#include<vector>
#include<queue>
#define maxn 100000+10
using namespace std;
int n, m, in[maxn], ans[maxn];
vector<int>G[maxn];
priority_queue<int>q;
int main(){
cin>>n>>m;
for(int i = 0; i < m; i++){
int a, b; cin>>a>>b;
G[b].push_back(a);
in[a]++;
}
for(int i = 1; i <= n; i++)
if(in[i]==0)q.push(i);
int num = n;
while(!q.empty()){
int t = q.top(); q.pop();
ans[t] = num--;
for(int i = 0; i < G[t].size(); i++)
if(--in[G[t][i]]==0)q.push(G[t][i]);
}
for(int i = 1; i <= n; i++)cout<<ans[i]<<" ";
return 0;
}