Pagini recente » Cod sursa (job #236212) | Cod sursa (job #2824508) | Cod sursa (job #1991317) | Cod sursa (job #987353) | Cod sursa (job #1726504)
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include<vector>
#include <stack>
#define maxn 50003
using namespace std;
vector <int> L[maxn];
stack <int> s;
int n, m, v[maxn];
void read()
{
int i, x, y;
scanf("%d %d", &n, &m);
for (i = 1; i <= m; i++)
{
scanf("%d %d", &x, &y);
L[x].push_back(y);
}
}
void DFS(int x)
{
v[x] = 1;
int i;
for (i = 0; i < L[x].size(); i++)
if (v[L[x][i]] == 0)
DFS(L[x][i]);
s.push(x);
}
void solve()
{
int i;
for (i = 1; i <= n; i++)
if (v[i] == 0)
{
DFS(i);
}
}
void afis()
{
while (!s.empty())
{
printf("%d ", s.top());
s.top();
}
}
int main()
{
freopen("sortaret.in", "r", stdin);
freopen("sortaret.out", "w", stdout);
read();
solve();
afis();
fclose(stdin);
fclose(stdout);
return 0;
}