Pagini recente » Cod sursa (job #2644868) | Cod sursa (job #2078873) | Cod sursa (job #3285230) | Cod sursa (job #504099) | Cod sursa (job #1573433)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
struct nod
{ int info;
nod *urm;
} *prim[50001];
int g[50001];
int n,m;
inline void Addnod(int x, int y)
{
nod *p=new nod;
p->info=y;
p->urm=prim[x];
prim[x]=p;
}
bool Cauta(int x, int y)
{ nod *p;
for(p=prim[x];p!=NULL;p=p->urm)
if(p->info==y) return true;
return false;
}
void Citire()
{ int i, x, y;
fin>>n>>m;
while(fin>>x>>y)
if(!Cauta(x,y))
{Addnod(x, y);
g[y]++;
}
}
void Sortare()
{ int nr=0,i;
nod *p;
while(nr<n)
{ for(i=1;i<=n;i++)
if(g[i]==0) {fout<<i<<" "; nr++; g[i]=-1;
for(p=prim[i];p!=NULL;p=p->urm) g[p->info]--;
}
}
}
int main()
{ Citire();
Sortare();
fin.close();
fout.close();
return 0;
}