Pagini recente » Cod sursa (job #1132097) | Cod sursa (job #1416223) | Cod sursa (job #2957511) | Cod sursa (job #686830) | Cod sursa (job #1011373)
#include<fstream>
#define nmax 50003
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
int d[nmax],n,m;
struct nod{
int x;
nod *urm;
};
nod *lista[nmax];
void adaugare(int a,int b)
{
nod *p;
p=new nod;
p->x=b;
p->urm=lista[a];
lista[a]=p;
}
void citire()
{
int a,b;
f>>n>>m;
for(int i=1;i<=n;i++)
d[i]=0;
for(int i=1;i<=m;i++)
{
f>>a>>b;
d[b]++;
adaugare(a,b);
}
}
void algoritm()
{
int i,j;
nod *p;
for (i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(d[j]==0)
break;
}
g<<j<<" ";
for(p=lista[j];p!=NULL;p=p->urm)
{
d[p->x]--;
}
d[j]=-1;
}
}
int main()
{
citire();
algoritm();
f.close();
g.close();
return 0;
}