Pagini recente » Cod sursa (job #1162005) | Cod sursa (job #2166391) | Cod sursa (job #615334) | Cod sursa (job #137336) | Cod sursa (job #2325989)
#include <fstream>
#include <vector>
using namespace std;
#define FILENAME "sortaret"
ifstream fin (FILENAME".in");
ofstream fout(FILENAME".out");
const int MAXN = 50000 + 16;
int Deg[MAXN], N, M;
vector < int > Suc[MAXN];
int main()
{
fin >> N >> M;
while(M--)
{
int from, to;
fin >> from >> to;
++Deg[to];
Suc[from].push_back(to);
}
int x = 1;
while(x <= N)
{
if(!Deg[x])
{
fout << x << ' ';
vector < int > :: iterator it;
int node = x;
for(it = Suc[node].begin();
it != Suc[node].end(); ++it)
{
--Deg[*it];
if(!Deg[*it] && *it < x + 1)
x = *it - 1;
}
}
++x;
}
return 0;
}