Pagini recente » Cod sursa (job #981706) | Cod sursa (job #1733492) | Cod sursa (job #1415252) | Istoria paginii runda/concurs12345/clasament | Cod sursa (job #3141332)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <vector>
#include <cstring>
#include <iterator>
#include <queue>
#define LIM 1<<17
/// TONI BO$$ was here
/// #MLC
using namespace std;
char BUF[LIM];
int poz;
int f[50001],rad[50001];
vector <int> L[50001];
vector <int> TONI_BO$$;
inline char getChar(){
poz++;
if(poz>=LIM){
fread(BUF,LIM,1,stdin);
poz=0;
}
return BUF[poz];
}
inline int getNr(){
int r=0, semn=1;
char ch=getChar();
while(isdigit(ch)==0 && ch!='-') ch=getChar();
if(ch=='-'){
semn=-1;
ch=getChar();
}
while(isdigit(ch)!=0){
r=r*10+semn*(ch-'0');
ch=getChar();
}
return r;
}
int main()
{
int i,n,m,a,b,k;
freopen("sortaret.in","r",stdin);
freopen("sortaret.out","w",stdout);
n=getNr();
m=getNr();
while(m--)
{
a=getNr();
b=getNr();
L[a].push_back(b);
rad[b]++;
}
queue <int> q;
for(k=1; k<=n; k++)
if(!rad[k])
q.push(k);
while(!q.empty())
{
int x = q.front();
q.pop();
printf("%d ", x);
for(auto it : L[x]){
rad[it]--;
if(!rad[it])
q.push(it);
}
}
return 0;
}