Pagini recente » Cod sursa (job #2500450) | Cod sursa (job #2354321)
// sortare_topologica.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
//#include "pch.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int viz[50000],n,m;
int a[5000][5000];
list<int> l;
void adancime(int k)
{
viz[k] = 1;
for (int i = 1; i <= n; i++)
{
if (a[k][i] and !viz[i])
adancime(i);
}
l.push_front(k);
}
int main()
{
vector<int> v;
fin >> n >> m;
list<int>::iterator k;
int i, j;
while (fin >> i >> j)
{
a[i][j] = 1;
}
adancime(1);
for (k = l.begin(); k != l.end(); k++)
fout << *k<<" ";
}