Mai intai trebuie sa te autentifici.
Cod sursa(job #2262613)
| Utilizator | Data | 17 octombrie 2018 17:24:44 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 40 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.7 kb |
#include<fstream>
#define Nmax 2000
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m;
int A[Nmax][Nmax],nrp[Nmax];
void citire();
int main()
{
citire();
int i,j,nr_nodprez=0,nr_nivel=0;
while(nr_nodprez<n)
{
for(i=1;i<=n;i++)
if(nrp[i]==0)
{
fout<<i<<" ";
nr_nodprez++;
nrp[i]=-1;
for(j=1;j<=A[i][0];j++)
nrp[A[i][j]]--;
}
fout<<'\n';
}
return 0;
}
void citire()
{
int i,x,y;
fin>>n>>m;
for(i=1;i<=m;i++)
{ fin>>x>>y;
A[x][0]++;
A[x][A[x][0]]=y;
nrp[y]++;
}
}
