Pagini recente » Cod sursa (job #2290938) | Cod sursa (job #244379) | Cod sursa (job #3271435) | Cod sursa (job #2373424) | Cod sursa (job #962182)
Cod sursa(job #962182)
#include <cstdio>
#include <vector>
using namespace std;
const int DMAX = 50003;
int S[DMAX], n;
bool V[DMAX];
vector <int> G[DMAX];
void DFS (int nod) {
V[nod] = 1;
for (int i = 0; i < G[nod].size(); ++i)
if (!V[G[nod][i]])
DFS (G[nod][i]);
S[++n] = nod;
}
int main () {
freopen ("sortaret.in", "r", stdin);
freopen ("sortaret.out", "w", stdout);
int N, M, i, a, b;
scanf ("%d%d", &N, &M);
for (i = 1; i <= N; ++i)
scanf ("%d%d", &a, &b),
G[a].push_back(b);
for (i = 1; i <= N; ++i)
if (!V[i])
DFS (i);
for (; n >= 1; --n)
printf ("%d ", S[n]);
printf ("\n");
}