Pagini recente » Cod sursa (job #2754469) | ichb-locala-2013-11-12 | Cod sursa (job #2594890) | Cod sursa (job #2199868) | Cod sursa (job #1207049)
#include <fstream>
#include <vector>
#define DIM 50010
using namespace std;
vector<int> L[DIM];
int v[DIM];
int d[DIM];
int S[DIM];
int n, m, i, k, x, y;
using namespace std;
void dfs(int nod) {
v[nod] = 1;
for (int i=0;i<L[nod].size();i++)
if (v[ L[nod][i] ] == 0)
dfs( L[nod][i] );
S[++k] = nod;
}
int main (){
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
fin>>n>>m;
for (i=1;i<=m;i++) {
fin>>x>>y;
L[x].push_back(y);
d[y]++;
}
for (i=1;i<=n;i++)
if (d[i] == 0)
dfs(i);
for (i=n;i>=1;i--)
fout<<S[i]<<" ";
return 0;
}